NFT airdrop whitelist made easy!

Muhammad
4 min readFeb 28, 2022

--

To implement whitelist using merkle tree and do an airdrop first ofcourse you need to have a list of addresses that you want to create whitelist for and for this article im gonna be using some example addresses below.

I simply created an array of addresses that i want to be in airdrop aka whitelist for my next big upcoming airdrop now what i want is to have a hashed root to verify all these addresses or to verify a single user if that user was included in the list or not of our hashed root we are gonna use to verify each user in our smart contract right?

You’ll have create a folder “You can name it anything” and then create an app in that folder by running

npm init -y

You should have at this point package.json file in your folder that you created and you need to install two packages called “MerkleTree” and “keccak256” and then require those packages your code should look like this,

Now remember we have an array as well and we now have these two packages installed? alright so lets create our merkle tree.

What the above code is doing is basically its creating hashes of the list of addresses that we defined above and its creating merkle tree using those addresses that have been hashed using keccak256 😊.

Now at this point we have Merkle tree and we can get the user proof from our merke tree to verify user on our smart contract but we need our root from this merkle tree which we’ll be adding on smart contract and then use that root root to verify the proofs for a specific address that we pass from the frontend for our user while that user tries to mint NFT.

This is how we get our root of merkle tree for verification of whitelisted users on smart contract and this root should be saved in smart contract.

To verify on smart contract we’ll need the merkle proof of the address that mints the NFT for that we can simply generate the merkletree and get hex proof for specific user when the wallet connects.

The above code gets the hex proof for the verification on smart contract for that specific wallet address (it is up to you how you want to implement this solution).

Lets move to the smart contract side of verification & for that we need merkleproof library to import in our smart contract.

Your airdrop function should look something like if its not doing anything complex & just take a look at the

This one what this part is doing basically its verifying the sender who executed the transaction and its simply verifying the merkleproof that we passed along with the user wallet address which is a combination of creating our root and generating our merkletree and the proof we passed was for this specific wallet.

😮‍💨 at this point you should have implemented a merkletree and it you still have problem or you cant really figure it out or any part of it feel free to write me or ask anything i would love to answer thanks!

--

--

Muhammad
Muhammad

Written by Muhammad

Studying Project Management and business with a highly techincal background in Software Engineering towards a Project Management and business oriented career

No responses yet