DEV Community

Murat Can Yüksel
Murat Can Yüksel

Posted on

Basic explanation of how whitelisting works in Solidity

You know what whitelisting is, but you also want to understand how it works under the hood. Now imagine you have an NFT collection, and you tell the community that people who buy your NFTs right now will have priority access to the upcoming online game you and your team have been developing.

How does that whitelisting actually occurs? How is it structured in solidity?

Almost always, the addressess that purchase the NFT will be added into a mapping. According to alchemy a mapping is a hash table in Solidity that stores data as key-value pairs. They are defined like:

mapping(address => bool) public whitelistedAddresses;
Enter fullscreen mode Exit fullscreen mode

You see, the idea here is simple: When someone purchases one of your NFTs, you take their address, and put a truthy statement to it. That's what a bool is, it's a boolean. True, or false. If they have not purchased your NFT, their addresses will not be in the mapping anyway, so it will not be a truthy statement. When they do purchase, on inquiry their addresses will return a truthy statement and you'll know that they are whitelisted.

Then, you can basically do whatever you want with this whitelistedAddresses mapping. You can use it as a guard to certain functions and only whitelisted people can do such and such.

Top comments (0)