This project implements an advanced NFT contract with cutting-edge features such as Merkle Tree-based airdrops, bitmap optimizations, commit-reveal random allocation, multicall for efficient transfers, and a state machine to control minting phases. The project is designed for scalability, security, and gas efficiency, leveraging OpenZeppelin libraries.
-
Addresses in the Merkle Tree are allowed to mint NFTs during the presale.
-
The contract supports two tracking mechanisms:
- Mapping: A traditional approach using a mapping to track addresses.
- Bitmap: A gas-optimized method using OpenZeppelin’s BitMaps.
- Ensures randomness during the NFT allocation process.
- Users commit a hash (NFT ID + secret) and reveal it after a delay of 10 blocks.
- Inspired by Cool Cats NFT but implemented without Chainlink.
- Enables batch processing of NFT transfers in a single transaction.
- Prevents abuse by ensuring only allowed functions can be multicalled.
-
The contract operates in distinct phases:
- Paused: No minting allowed.
- Presale: Merkle Tree-based minting using mapping or bitmap.
- Public Sale: Commit-reveal minting and multicall allowed.
- Sold Out: Minting disabled.
-
Each phase is enforced using require statements.
- Contributors can withdraw funds individually using the pull pattern, improving security.
- Allows withdrawals to multiple contributors.
- Utilizes bitmap tracking for airdrop eligibility to reduce storage costs.
- Leverages OpenZeppelin’s nonReentrant modifier to prevent reentrancy attacks.
AdvancedNFT/
├── contracts/
│ └── advancednft.sol # Main NFT contract implementation
├── merkletree/
│ ├── merkleproof.mjs # Script to generate Merkle Tree and proofs
│ ├── tree.json # Serialized Merkle Tree data
│ ├── package.json # Dependencies for the Merkle Tree scripts
│ └── .gitignore # Ignore unnecessary files
├── answers.md # Answers to important questions
├── README.md # Documentation for the project
- Node.js: To run the Merkle Tree scripts.
- Solidity Compiler: For compiling the contract.
- Clone the repo:
clone https://github.com/username/AdvancedNFT.git
cd AdvancedNFT
- Generate merkletree and proof or use existing ones.:
cd merkletree
npm install
- Deploy the contract using Hardhat or Remix.
Run the merkleproof.mjs
script to generate the Merkle Root and proofs:
node merkletree/merkleproof.mjs
Use the generated root and proofs in the contract.
Use mintWithMapping
or mintWithBitmap
with a valid Merkle Proof.
-
Get commit hash: Use the following command in the console to generate the commit hash:
web3.utils.keccak256( web3.eth.abi.encodeParameters( ["uint256", "uint256"], [replace_with_nftId, replace_with_secret] ) );
-
Commit:
commit(hash);
- Reveal (after 10 blocks):
reveal(nftId, secret);
Prepare calldata using generateTransferFromData and call multicall with the encoded data.
Contributors can call withdraw() to claim their funds securely.
- OpenZeppelin Contracts: Security and gas-efficient libraries.
- Hardhat: Testing and deployment.
- Merkle Tree Utilities: For secure airdrops.
- Solidity 0.8.x: Latest features with built-in overflow checks.
- Fork the repository.
git checkout -b feature-name
- Submit a pull request.
This project is licensed under the MIT License.