This project demonstrates how to implement a whitelist system for NFT minting using Merkle trees and proofs on both Ethereum (Solidity) and Aptos (Move) blockchains.
The project consists of:
- A Solidity contract (
WhitelistedNFT
) that implements an ERC721 token with whitelist verification using Merkle proofs - A Move module for Aptos (
WhitelistedNFT
) that implements NFT minting with whitelist verification - JavaScript utility functions for generating Merkle trees and proofs from a list of addresses
- Test scripts to verify the functionality
- A CLI utility to manage the whitelist and generate proofs
npm install
npm run compile
npm test
npm run deploy
npm run interact
The project includes a command-line utility for managing the whitelist:
npm run whitelist -- <command> [params]
Available commands:
add <address>
- Add an Ethereum address to the whitelistremove <address>
- Remove an address from the whitelistlist
- List all whitelisted addressesroot
- Generate and display the Merkle Rootproof <address>
- Generate a Merkle Proof for a specific address
Examples:
# Add an address to the whitelist
npm run whitelist -- add 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
# List all addresses
npm run whitelist -- list
# Generate the Merkle root to deploy with your contract
npm run whitelist -- root
# Generate a proof for a specific address (for minting)
npm run whitelist -- proof 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
The aptos/
directory contains a Move implementation of the WhitelistedNFT concept for the Aptos blockchain.
cd aptos
aptos move compile
aptos move test --dev
merkle_proof.move
: Implements Merkle tree verification logicwhitelisted_nft.move
: Implements the main NFT functionality with whitelist verificationwhitelisted_nft_tests.move
: Tests for the WhitelistedNFT module
- ✅ Full Merkle tree whitelist verification
- ✅ NFT minting with whitelist controls
- ✅ Access control for updating the whitelist
The scripts/generateAptosProof.js
file demonstrates how to generate Merkle proofs for use with the Aptos implementation.
node scripts/generateAptosProof.js
Note: There are currently compatibility issues between the JavaScript and Move implementations due to differences in address serialization. See the Aptos README for more details.
- We create a list of whitelisted addresses
- Generate a Merkle tree where each leaf is a hashed address
- Store only the Merkle root in the smart contract/module
- When a user wants to mint an NFT, they provide a Merkle proof that verifies their address is part of the whitelist
- The contract verifies the proof and allows minting if valid
contracts/WhitelistedNFT.sol
: The Ethereum NFT contract with Merkle verificationaptos/sources/whitelisted_nft.move
: The Aptos NFT module with Merkle verificationaptos/sources/merkle_proof.move
: Merkle proof verification for Aptosscripts/merkleUtils.js
: Utility functions for Merkle tree operationsscripts/generateAptosProof.js
: Utility to generate proofs for Aptos
- The Merkle root is immutable once set, but can be updated by the contract owner
- Each address can only mint once
- The contract has a max supply cap