DEV Community

Cover image for Create a whitelist for your NFT project

Create a whitelist for your NFT project

Abdul Rauf on January 05, 2022

Many NFT projects have been using whitelists/allowlists to reward their most active community members. The members in this list are allowed to mint...
Collapse
 
efe_acikgoz_f372e7abe3ba6 profile image
Efe Acikgoz

While this is a great solution, it comes with great cost haha. The gas cost per address is 20k, so it costs around 0.0035 eth per address added, and if you have A LOT of addresses, this will start to become a problem

Collapse
 
lilcoderman profile image
Abdul Rauf

Thanks for sharing! Do you know a better way to do the whitelist?

Collapse
 
efe_acikgoz_f372e7abe3ba6 profile image
Efe Acikgoz

Depending on your use case using a patricia tree or using signatures can save a lot of gas.

For example you can create an empty wallet and use it’s private key to sign a message on your backend that your contract can recreate and use ecrecover to check if the address is correct.

Thread Thread
 
lilcoderman profile image
Abdul Rauf

Do you know any good resource explaining this? Or maybe a smart contract using this technique?

Thread Thread
 
efe_acikgoz_f372e7abe3ba6 profile image
Efe Acikgoz

Patricia tree or signatures?

Thread Thread
 
lilcoderman profile image
Abdul Rauf

You can share whatever you can πŸ™‚

Thread Thread
 
efe_acikgoz_f372e7abe3ba6 profile image
Efe Acikgoz

bytes32 hash = keccak256(abi.encodePacked(this, msg.sender, quantity, tier));
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 prefixedHashMessage = keccak256(abi.encodePacked(prefix, hash));
address signer = ecrecover(prefixedHashMessage, _v, _r, _s);
require(signer == serverAddress, "Invalid signature");

The contract will expect a message signed with contract address, sender address, how many you need to buy and the price tier. Even if the message is intercepted and changed, the sign will be invalid because it will be different than what the server's signed message. For example if the server signed a message with 1 quantity at tier4 pricing, you cannot change the variables to 5 mints at tier1 because the contract side generated hash will be different and transaction will fail.

I'm sure in time we will be able to handle all of these with web3 solutions but for now I think we still need a mixed solution due to gas prices

Thread Thread
 
bronteraspital profile image
bronteraspital

this sounds pretty interesting. I'm in the process of finishing up my own NFT project and can't afford the gas fee to set up a whitelist. How much cheaper do you think this would come out to relatively?

Thread Thread
 
efe_acikgoz_f372e7abe3ba6 profile image
Efe Acikgoz

Ecrecover costs 3000 gas, so it will save 17k gas per adress

Thread Thread
 
corentindallenogare profile image
corentinDallenogare

Hello, could you also do a little tutorial? Thank you

Thread Thread
 
bronteraspital profile image
bronteraspital

Sounds great! By any chance would you be able to help me implement this method in my whitelist? I can send you a percentage of sales!

Thread Thread
 
redcomethk profile image
Ralph Chan

I found another NFT Project, MetaAngels, which should be doing the whitelist in this approach. The contract location is: etherscan.io/address/0xad265ab9b99...

Collapse
 
cvega21 profile image
Christian Vega-Munguia

this is great, thank you!! looked this up after the fishy fam fiasco, their contract only checked for the current NFT balance of the WL minter in the WL mint function. so they could just transfer out the tokens and keep minting more. unfortunate, but very easy fix.

thanks to this tutorial, i am confident we will not be facing the same issue in our mint 😸

Collapse
 
lilcoderman profile image
Abdul Rauf

Wow! I'm glad you found this helpful. Also, I'd love to know more about your project 😁

Collapse
 
catsmeow profile image
cat mie

This is a great article. Thank you! I am wondering if this approach is practical if setAllowList() is used within an contract running on Polygon with an allowList array size of ~9000? What interface could I use to input such an array to the instantiated contract? Etherscan seems to have a limit on the size of the array that can be inputted.

Collapse
 
loobj126 profile image
loobj126 • Edited

Hi sir , I try load this contract in remix . This is step i perform however it doesnt work

1) setIsAllowListActive = true
2) setAllowList - put an address and numallowedtomint =1

The error execption has trriggered

transact to Doodles.setAllowList errored: Error encoding arguments: Error: expected array value (argument=null, value="0x623CD18A2344476063Ee2f806EEdDdbcE9cd5499", code=INVALID_ARGUMENT, version=abi/5.5.0)

Can you pls advise ?

dev-to-uploads.s3.amazonaws.com/up...

Collapse
 
loobj126 profile image
loobj126

Hi Rauf , can you pls advise

Collapse
 
nakedrunnersnft profile image
Naked Runners NFT

Hey! Thank you for this write-up. I'm building a NFT project around mindfulness-based running community, and learning more about smart contracts to add whitelist and tier functions to it (after learning from Hashlips on YouTube).

This might be a stupid question, but I don't see any Whitelists on Doodle's current smart contract. My understanding is that you need to have the addresses with WL access need to be in the smart contract so they can be verified by the owner's contract. Is that because they had it on only for the pre-sale, and removed the addresses from the contract after that? Or is the contract able to retrieve the list of WL addresses out side of the contract code? Much thanks! πŸ™πŸ½

Collapse
 
mohmmadanas profile image
Mohmmadanas

This is amazing 🀩 Thank You
But I have question
I want ask about the NFT price
How we can make another price for whitelist user’s?

Collapse
 
lilcoderman profile image
Abdul Rauf

Sorry for the late reply!

You can create two separate payable functions. One for public mint and one for the whitelisted members. You can use require to check if someone's paying the right amount.

Public mint function

function mint() public payable {
    ...
    require(msg.value == PRICE, "Insufficient payment, 0.02 ETH per item");
    ...
  }
Enter fullscreen mode Exit fullscreen mode

Whitelist mint function

function mintPresale() public payable {
    ...
    require(msg.value == WHITELIST_PRICE, "Insufficient payment, 0.01 ETH per item");
    ...
  }
Enter fullscreen mode Exit fullscreen mode

Let me know if this answers your question.

Collapse
 
jacob_cai_83b53cda1c3959a profile image
Jacob Cai

How and where do people pay for their guaranteed nft ?