Skip to content

QuickosssLabs/Dgenz_onchain_Opensource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dgenz Onchain NFT

A fully on-chain generative NFT project that guarantees configurable rarity for each trait and strict uniqueness of every NFT (no duplicate combinations possible). All traits and images are generated and stored on-chain using Solidity smart contracts.

πŸš€ Key Features

  • 100% On-Chain: All images and metadata generated on-chain
  • Configurable Rarity: Fine-tune rarity weights via JSON configuration
  • Guaranteed Uniqueness: No duplicate trait combinations possible
  • Multi-Phase Minting: GTD (free), Whitelist, and Public phases
  • Automatic Verification: All contracts verified on BaseScan
  • Web3 Integration: Includes a minting dapp

πŸ“ Project Structure

Dgenz_Onchain/
β”œβ”€β”€ πŸ“ layers/                    # PNG trait images (organize by category)
β”œβ”€β”€ πŸ“ svgs/                     # Generated SVGs (auto-generated)
β”œβ”€β”€ πŸ“ contracts/                # Solidity smart contracts
β”‚   β”œβ”€β”€ DgenzOC.sol             # Main NFT contract
β”‚   β”œβ”€β”€ SVGAssembler.sol        # SVG assembly contract
β”‚   β”œβ”€β”€ DgenzTraits.sol         # Trait definitions library
β”‚   β”œβ”€β”€ DgenzRarity.sol         # Rarity calculation library
β”‚   β”œβ”€β”€ BackgroundRenderer.sol   # Background SVG renderer
β”‚   β”œβ”€β”€ RaceRenderer.sol         # Race SVG renderer
β”‚   β”œβ”€β”€ OutfitRenderer.sol       # Outfit SVG renderer
β”‚   β”œβ”€β”€ EyesRenderer.sol         # Eyes SVG renderer
β”‚   β”œβ”€β”€ TopHeadRenderer.sol      # Top head SVG renderer
β”‚   β”œβ”€β”€ AccessoryRenderer.sol    # Accessory SVG renderer
β”‚   β”œβ”€β”€ MouthRenderer.sol        # Mouth SVG renderer
β”‚   └── CheckmarkRenderer.sol    # Checkmark SVG renderer
β”œβ”€β”€ πŸ“ scripts/                  # Deployment and utility scripts
β”œβ”€β”€ πŸ“ webapp/                   # Minting dapp (Next.js)
β”œβ”€β”€ πŸ“„ generate_all.js           # Main generation script
β”œβ”€β”€ πŸ“„ compile_and_deploy.js     # Full deployment workflow
β”œβ”€β”€ πŸ“„ import_allowlist.js       # Allowlist import utility
β”œβ”€β”€ πŸ“„ update_webapp.js          # Webapp configuration updater
β”œβ”€β”€ πŸ“„ calculate_bytecode_size.js # Contract size calculator
β”œβ”€β”€ πŸ“„ calculate_total_combinations.js # Trait combination calculator
β”œβ”€β”€ πŸ“„ rarity_config.json        # Trait rarity configuration
β”œβ”€β”€ πŸ“„ shared_layers_order.json  # Layer ordering configuration
β”œβ”€β”€ πŸ“„ deployed_addresses.json   # Deployed contract addresses
β”œβ”€β”€ πŸ“„ gtd_list.csv              # GTD allowlist (CSV format)
β”œβ”€β”€ πŸ“„ whitelist.csv             # Whitelist allowlist (CSV format)
└── πŸ“„ README.md                 # This documentation file

βš™οΈ Configuration

Collection Parameters

Edit generate_all.js to customize your collection:

const TRAITS_LIB = 'DgenzTraits'; // Traits library name
const CONTRACT_NAME = 'DgenzOC'; // Contract name
const COLLECTION_NAME = 'Dgenz Onchain';  // Collection name
const SYMBOL = 'DGOC'; // Symbol
const COLLECTION_DESCRIPTION = '1069 Dgenz Onchain.'; // Collection description
const ROYALTY_FEE_BPS = 690; // 690 = 6,9% (in basis points)
const MAX_SUPPLY = 1069; // Max supply
const MAX_MINT_PER_ADDRESS_GTD = 1; // Max mint per address in GTD phase
const MAX_MINT_PER_ADDRESS_WHITELIST = 3; // Max mint per address in Whitelist phase
const MAX_MINT_PER_ADDRESS_PUBLIC = 5; // Max mint per address in Public phase
const WHITELIST_PRICE = '0.0003 ether'; // Price for whitelist mint
const PUBLIC_PRICE = '0.00069 ether'; // Price for public mint
const MINT_COUNT_ON_DEPLOY = 1; // Number of NFTs to mint during deployment

Layer Order

Configure the trait order in generate_all.js:

const LAYER_ORDER = [
  'Background',
  'Race', 
  'Outfit',
  'Eyes',
  'Top Head',
  'Accessory',
  'Mouth',
  'Checkmark'
];

🎨 Adding New Traits

  1. Add PNG files to appropriate layers/ subfolder
  2. Run generation: node generate_all.js
  3. Deploy: npx hardhat run compile_and_deploy.js --network base

πŸ› οΈ Quick Start

1. Installation

npm install

2. Environment Setup

Create a .env file:

PRIVATE_KEY=your_private_key
RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR_API_KEY
BASESCAN_API_KEY=your_basescan_api_key

3. Prepare Your Layers

Place PNG trait images in layers/ subfolders:

layers/
β”œβ”€β”€ Background/
β”œβ”€β”€ Race/
β”œβ”€β”€ Outfit/
β”œβ”€β”€ Eyes/
β”œβ”€β”€ Top Head/
β”œβ”€β”€ Accessory/
β”œβ”€β”€ Mouth/
└── Checkmark/

4. Configure Rarity (Optional)

node generate_rarity_config.js

Edit rarity_config.json to set trait weights.

5. Generate Contracts

node generate_all.js

6. Deploy to Mainnet

npx hardhat run compile_and_deploy.js --network base

🎯 Workflow Summary

flowchart TD
    A[Prepare PNG Layers] --> B[Configure rarity_config.json]
    B --> C[Run generate_all.js]
    C --> D[Contracts Generated]
    D --> E[Deploy with compile_and_deploy.js]
    E --> F[Contracts Deployed & Verified]
    F --> G[Set up allowlists]
    G --> H[Configure webapp]
    H --> I[Launch Collection]
Loading

πŸ—οΈ Smart Contract Architecture

graph TD
    A[DgenzOC - Main Contract] --> B[SVGAssembler]
    B --> C[BackgroundRenderer]
    B --> D[RaceRenderer]
    B --> E[OutfitRenderer]
    B --> F[EyesRenderer]
    B --> G[TopHeadRenderer]
    B --> H[AccessoryRenderer]
    B --> I[MouthRenderer]
    B --> J[CheckmarkRenderer]
    A --> K[DgenzTraits Library]
    A --> L[DgenzRarity Library]
Loading

Contract Components

  • DgenzOC: Main ERC721 contract with minting logic
  • SVGAssembler: Combines trait SVGs into final image
  • Renderer Contracts: Store SVG code for each trait
  • DgenzTraits: Trait definitions and metadata
  • DgenzRarity: Weighted random selection logic

πŸ”§ Advanced Usage

Minting Phases

The contract supports three minting phases:

  • GTD Phase (0): Free minting for GTD-listed addresses
  • Whitelist Phase (1): 0.0003 ETH for whitelist-listed addresses
  • Public Phase (2): 0.00069 ETH for everyone

Phase Management

# Set minting phase
npx hardhat run scripts/set_phase.js --network base 1

# Pause/Unpause minting
npx hardhat console --network base
const contract = await ethers.getContractAt("DgenzOC", "CONTRACT_ADDRESS");
await contract.pause(); // or await contract.unpause();

Batch Import Allowlist

# Import GTD list (adds to both GTD and Whitelist)
node import_allowlist.js gtd

# Import whitelist (adds to Whitelist only)
node import_allowlist.js whitelist

Create CSV files (gtd_list.csv, whitelist.csv) with one address per line.

Note: GTD addresses are automatically added to both GTD and Whitelist lists, while Whitelist addresses are only added to the Whitelist.

Webapp Setup

node update_webapp.js
cd webapp
npm install
# Add NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID to .env.local
# Edit page.tsx
npm run dev

πŸ” Contract Functions

🌐 Public Functions (Accessible to everyone)

  • mint(uint256 quantity) - Mint NFTs
  • tokenURI(uint256 tokenId) - Get token metadata and SVG image
  • getMintPrice(address minter) - Get mint price for a given address
  • getMaxMintPerAddress(address minter) - Get maximum mint per address
  • totalSupply() - Get total number of minted tokens
  • totalMinted() - Alias for totalSupply() (ERC721A compatibility)
  • currentPhase() - Get current minting phase (GTD, WHITELIST, PUBLIC)
  • supportsInterface(bytes4 interfaceId) - Check ERC interface support
  • getRoyaltyInfo(uint256 tokenId, uint256 salePrice) - Get royalty information

πŸ” Owner Functions (Owner only)

  • setPhase(MintPhase phase) - Change minting phase (GTD, WHITELIST, PUBLIC)
  • addToGTDList(address[] calldata addrs) - Add addresses to GTD list
  • addToWhitelist(address[] calldata addrs) - Add addresses to whitelist
  • pause() - Pause minting (emergency control)
  • unpause() - Resume minting after pause
  • withdraw() - Withdraw contract funds to owner
  • bumpRandomness(uint256 extra) - Improve entropy of random generation system

πŸ“Š View Functions (Read-only)

  • mintedPerAddress(address) - Number of tokens minted per address
  • isGTDListed(address) - Check if address is in GTD list
  • isWhitelistListed(address) - Check if address is in whitelist
  • tokenTraits(uint256 tokenId) - Get traits of a specific token
  • isCombinationMinted(bytes32 hash) - Check if a trait combination has already been minted

πŸ”§ Constants & Configuration

  • GTD_PRICE - Price for GTD phase (0 ETH)
  • WHITELIST_PRICE - Price for whitelist phase (0.0003 ETH)
  • PUBLIC_PRICE - Price for public phase (0.00069 ETH)
  • MAX_SUPPLY - Maximum supply (1069)
  • MAX_MINT_PER_ADDRESS_GTD - Max mint per address in GTD phase (1)
  • MAX_MINT_PER_ADDRESS_WHITELIST - Max mint per address in whitelist phase (3)
  • MAX_MINT_PER_ADDRESS_PUBLIC - Max mint per address in public phase (5)

🎲 Random Generation System

  • _generateSeedFromHash(bytes32 hash, uint256 salt) - Generate random seed from hash
  • _generateTraitsFromHash(bytes32 hash) - Generate traits from hash
  • _random(uint256 tokenId, uint256 salt) - Internal random generation function
  • _random(uint256 tokenId, uint256 salt, uint8 max) - Version with maximum limit

🎨 SVG & Metadata Generation

  • _buildAttributes(Traits memory t) - Build JSON attributes for metadata
  • _addAttribute(string memory result, bool first, string memory traitName, string memory traitValue) - Add attribute to metadata
  • _attribute(string memory trait_type, string memory value) - Format individual attribute
  • _base64(bytes memory data) - Encode data to base64 for image URIs

πŸ“‘ Events

  • Minted(address indexed minter, uint256 indexed tokenId) - Emitted when minting a token
  • Withdrawn(address indexed to, uint256 amount) - Emitted when withdrawing funds
  • PhaseChanged(MintPhase indexed oldPhase, MintPhase indexed newPhase) - Emitted when changing phase

πŸ›‘οΈ Security Best Practices

  • Never share private keys - Use dedicated wallets
  • Test on testnets - Deploy to Base Sepolia first
  • Fund your wallet - Ensure sufficient ETH for gas
  • Review contracts - Check generated code before mainnet

πŸ“‹ Requirements

  • Node.js >= 18
  • Hardhat
  • Base network RPC URL
  • BaseScan API key
  • Wallet with ETH for gas

πŸ”— Useful Links

πŸ†˜ Troubleshooting

Common Issues

"Stack too deep" errors

  • Ensure viaIR: true in hardhat.config.js
  • Reduce number of traits per layer

Environment variable errors

  • Use npx hardhat run instead of node
  • Check .env file configuration

Contract verification fails

  • Wait 10-15 seconds after deployment
  • Check constructor arguments match

Minting fails

  • Check current phase and pricing
  • Ensure wallet has sufficient ETH
  • Verify contract is not paused

πŸ“ž Support

For questions or support:

πŸ“„ License

MIT License


Ready to launch your on-chain NFT collection! πŸš€

About

Opensource app to deploy your own 100% onchain NFT collection

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors