Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamic NFT Card - On-chain ENS & Balance

A fully on-chain dynamic NFT that displays the owner's ENS name and ETH balance with generated text based on balance thresholds. All metadata and SVG are stored on-chain with no external dependencies.

🎨 Features

  • Fully On-chain: All metadata and SVG generated on-chain
  • Dynamic Content: Updates based on:
    • Owner's ENS name (or address if no ENS)
    • Owner's ETH balance (with 5 decimal precision)
    • Generated motivational text based on balance
  • OpenSea Compatible: Inherits from ERC721SeaDrop for full marketplace compatibility
  • Modular Architecture: Separated into three contracts for clean code organization

📋 Contract Address

Mainnet: [INSERT_CONTRACT_ADDRESS_HERE]

Sepolia Testnet: 0xAd7d830A332239fd95058aD058F2Db2128b56e7b

🏗️ Architecture

The project consists of three main contracts:

1. NFTCard.sol (Main Contract)

The core ERC721 contract that combines all functionality and generates the dynamic tokenURI.

contract NFTCard is ERC721SeaDrop, SVG, ENSManager

2. ENSManager.sol

Handles all ENS integration to retrieve the owner's ENS name from on-chain data.

Key Features:

  • Queries ENS reverse registrar to get the node for an address
  • Resolves the node to get the resolver address
  • Retrieves the ENS name from the resolver
  • Falls back to displaying the address if no ENS name exists
function getName(address _user) public view returns (bool, string memory name)

3. SVG.sol

Contains all SVG constants and styling for the NFT card generation.

Features:

  • Gold gradient styling
  • Matte black background
  • Structured text elements for balance, status text, and owner info

🎯 Dynamic Text Generation

The NFT displays different text based on the owner's balance:

  • < 1 ETH: "Try harder bro"
  • 1-10 ETH: "Well, thats not bad"
  • > 10 ETH: "Proof-of-Degen"

Balance is displayed with 5 decimal precision (e.g., "2.50000 Ether")

🚀 Installation

Prerequisites

Setup

  1. Clone the repository:
git clone <your-repo-url>
cd NFT
  1. Install dependencies:
forge install
  1. Create a .env file in the root directory:
cp .env.example .env
  1. Fill in your .env file with your credentials:
# RPC URLs
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_KEY

# Private Key (WITHOUT 0x prefix)
PRIVATE_KEY=your_private_key_here

# Etherscan API Key (works for both testnet and mainnet)
ETHERSCAN_API_KEY=your_etherscan_api_key_here

⚠️ Security Warning: Never commit your .env file! Make sure it's in .gitignore.

🧪 Testing

Run tests with verbose output:

make test

Run tests with debug mode:

make test-debug

Or using forge directly:

forge test -vvvv

📦 Deployment

Deploy to Sepolia Testnet

make deploy-sepolia

This command will:

  • Compile the contracts with optimization
  • Deploy to Sepolia
  • Automatically verify on Etherscan
  • Display gas costs and contract address

Deploy to Ethereum Mainnet

make deploy-mainnet

Note: This command includes a confirmation prompt to prevent accidental mainnet deployments.

Expected deployment cost at 0.268 gwei: ~$5-6 USD (based on ~6M gas)

📝 Makefile Commands

The project includes a Makefile for easy command execution:

Command Description
make test Run all tests with verbose output (-vvvv)
make test-debug Run tests in debug mode for step-by-step execution
make deploy-sepolia Deploy to Sepolia testnet with verification
make deploy-mainnet Deploy to Ethereum mainnet with verification (includes confirmation)
make help Display all available commands

🔧 Configuration

Foundry Configuration

The project uses aggressive optimization settings in foundry.toml:

  • Default profile: optimizer_runs = 200, via_ir = true
  • Sepolia profile: optimizer_runs = 10000 (optimized for deployment cost)
  • Mainnet profile: optimizer_runs = 1000000 (maximum size optimization)

These settings reduce the contract size from 32,931 bytes to 20,814 bytes, fitting within the 24,576-byte limit.

🎨 SVG Generation

The NFT card features:

  • Gold gradient styling with multiple color stops
  • Matte black background with rounded corners
  • Dynamic balance display with 5 decimal places
  • ENS name or address display at the bottom
  • Status text that changes based on balance

Example output:

┌─────────────────────────────────┐
│                                 │
│         MrPicule fam            │
│                                 │
│  Your balance is 2.50000 Ether  │
│                                 │
│    Well, thats not bad          │
│                                 │
│                                 │
│         MrPicule.eth            │
└─────────────────────────────────┘

🔍 Key Technical Details

Contract Size Optimization

  • Original size: 32,931 bytes ❌
  • Optimized size: 20,814 bytes ✅
  • Achieved through via_ir = true and high optimizer_runs

Gas Costs

  • Sepolia deployment: ~4.8M gas
  • Estimated mainnet: 6M gas ($5-6 at 0.268 gwei)

ENS Integration

The contract integrates with ENS using:

  • IReverseRegistrar - to get the node for an address
  • ENS registry - to resolve the node to a resolver
  • INameResolver - to get the actual name

All queries are view functions with no gas cost for reading.

📄 License

MIT License - see LICENSE file for details

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🔗 Links

📧 Contact

Created by MrPicule - GitHub


Built with ❤️ using Foundry and Solidity

About

Simple representation of Dynamic NFT by Vantana

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages