Merkle Mint NFTs

Use a Merkle tree of possible artworks and then submit a proof it is valid to mint.

Branch Info

Author: Austin Griffith Source code: https://github.com/scaffold-eth/scaffold-eth-examples/tree/merkle-root-buyer-mints Intended audience: Beginners/Intermediate Topics: Scaffold-eth basics, NFTs, Merkle Tree

🏃‍♀️ Quick Start

Deployer pays around (0.283719 ETH ~$500 at todays gas and price) for the initial contract but then NFTs are only minted once a buyer wants them. (The buyer of the NFT pays the gas to mint. ~$55)
Table of Contents

About The Project

This branch uses the concept of merkel root to verify on chain NFT minting. So instead of pushing all verfied NFT hashes on-chain which would be quite expensive we generate a merkel root by modifying these scripts to make our life easier.

Getting Started


You have to know what is an ERC721 standard and what is NFT. Please refer to this and this for more information if you are not familiar with these terms.


Let's start our environment for tinkering and exploring how NFT auction would work.
  1. 1.
    Clone the repo first
git clone https://github.com/scaffold-eth/scaffold-eth-example.git buyer-mints-nft
  1. 1.
    Install dependencies
yarn install
  1. 1.
    Start local chain ina different terminal
yarn chain
  1. 1.
    Start your React frontend
yarn start
  1. 1.
    Deploy your smart contracts to a local blockchain
yarn deploy

Smart contracts

Let's navigate to packages/hardhat/contracts folder and check out what contracts we have there.
We use a couple of contracts in this dApp.


All the logic that verifies minting a particular NFT sits here. When you run yarn deploy a merkel root is generated and then passed in this contracts constructor while deploying.
claim is the main function which a buyer can call and mint a particular nft.
function claim(uint256 index, string calldata tokenURI, bytes32[] calldata merkleProof)
These are the arguments passed while sending the transaction, the merkel prrof and index are generated for each NFT at the time of the proof, navigate through this file for more info.
require(MerkleProof.verify(merkleProof, merkleRoot, node), 'MerkleDistributor: Invalid proof.');
This is the line where the proof verification takes place so if any NFT which was not a part of the merkel root generation is minted the transaction will revert.
If the proof validates the NFT is then minted to the buyer.


When you navigate to the react app on your browser you'll see the NFT's for which the merkel root was generated
💦 Use the faucet wallet icon in the bottom left of the frontend to give your address $1000 in testnet ETH.
🎫 Try to "Mint" an NFT:
and voilà you see your address as the owner after on-chain verification.