APIs used:
  • Check ownership in NFT collection  

Welcome to this comprehensive tutorial on creating an NFT Allowlist, your gateway to understanding NFTs and how to build an Allowlist smart contract on the Ethereum blockchain. Non-fungible tokens (NFTs) have changed how we own digital assets and track their history. In this guide, we'll talk about NFT Allowlists and why they matter. I'll also walk you through building your own NFT Allowlist smart contract step by step. Let's get started!

Prerequisites

Before diving into this tutorial, it is important to ensure you have a foundation in the following areas:

  • Basic understanding of NFTs.

  • Familiarity with solidity smart contract development.

Overview of NFTs (ERC 721)

NFTs, or Non-Fungible Tokens, are unique digital identifiers. Unlike cryptocurrencies like Bitcoin or USD, NFTs are distinct and carry specific information that sets them apart. They are used in various areas, such as collectibles, digital art, access keys, in-game assets like game characters, virtual real estate, music, etc. NFTs prove ownership of digital items on a blockchain, ensuring authenticity and history tracking.

The ERC-721 Token standard provides a standard interface for non-fungible tokens in smart contracts. This standard enables the tracking and transfer of NFTs, introducing uniqueness and value differentiation among other tokens. Each NFT has a unique token, making it globally different within its contract.

Popular marketplaces like OpenSea and Rarible facilitate the buying, selling, and trading of NFTs, reshaping digital ownership across various industries. NFTs have a lot of potential uses as they continue to spark discussions about their future significance.

What is an NFT Allowlist?

An NFT allowlist is a list of wallet addresses that have been granted exclusive access to mint an NFT collection -it’s also known as a whitelist. It’s a way that many NFT projects reward early supporters and build hype for their upcoming launch. Here's another use case: Imagine you run a Web3 academy and want users to earn an NFT certificate after taking courses on your platform, but it's a paid feature. You can use an NFT allowlist to ensure only paying participants can mint these certificates. Keep in mind that this is just another use case; there are many others. The key idea is that only specific addresses can mint certain NFTs based on specific conditions. Now, let’s talk about how NFT allowlists work.

How Do NFT Allowlists Work?

NFT allowlists are implemented using smart contracts. These contracts store a list of approved wallet addresses in their state and check their validity before allowing users to mint NFTs. In the Web3 academy example, the smart contract would verify if a user has paid for the certificate before minting it; otherwise, the process is rejected.

How to Get on An NFT Allowlist for a Project

The way to get on an NFT allowlist will vary depending on the project. Some projects will select whitelisted users randomly, while others will require users to meet certain criteria, such as being active in the project's Discord server, following the project on social media, or performing some other specific tasks.

Benefits of NFT Allowlists

There are several benefits of an NFT allowlist:

  • NFT allowlists provide a means to grant exclusive access to specific users, creating a sense of exclusivity and privilege.

  • They allow NFT projects to reward early supporters or those who meet specific criteria.

  • For Web3 businesses and creators, allowlists enable monetization by ensuring that only paying users can mint certain NFTs.

  • NFT allowlists prevent unauthorized access and minting, enhancing security and trust.

Problems Addressed by NFT Allowlists

  • Without allowlists, anyone could participate in NFT minting, potentially leading to unauthorized or undesired minting.

  • NFT allowlists address fairness concerns, ensuring that only eligible individuals, such as paid participants, can access specific NFTs.

  • Allowlists help combat speculative buying and ticket reselling issues in NFT markets.

Alternate Solutions

Here are some suggested alternate solutions for NFT allowlists:

  • Staking: Here, users are required to stake a certain amount of cryptocurrency to earn rewards and to be included on the allowlist. This is a way to reward long-term supporters of a project. An example is Moonbirds; Moonbirds is an NFT collection that requires users to stake a certain amount of ETH to be included on their allowlist.

  • Bidding: Here, users bid on a limited number of spots on the allowlist. This is a way to ensure that only the most dedicated users are included on the allowlist. An example is VeVe, an NFT marketplace that uses bidding to select whitelisted users for limited-edition NFT drops.

  • Raffle: This is where users are randomly selected to be included on the allowlist. This is a fair way to select whitelisted users, but it can be difficult to ensure that all users have an equal chance of being selected.

  • Queue: Users are placed in a queue and are allowed to mint NFTs in the order in which they joined the queue. This is a more fair way to select whitelisted users than a raffle, but it can lead to long wait times for users. Bored Ape Yacht Club, one of the most popular NFT collections, used a queue method to select whitelisted users.

The best alternative solution for an NFT allowlist will depend on the project's specific needs. If the project wants to be fair to all users, then a raffle or queue may be the best option. If the project wants to reward long-term supporters, then staking may be the best option. If the project wants to ensure that only the most dedicated users are included on the allowlist, then bidding may be the best option.

Tutorial: Creating an NFT Allowlist

We're now at the tutorial where I'll provide you with clear instructions for creating an NFT Allowlist smart contract. This involves building a smart contract that limits specific actions, such as minting an NFT, to a set of approved Ethereum addresses and so on. I'll walk you through the process of writing this contract using Remix.

1

Setting Up the Development Environment

Go to Remix Ethereum IDE here, and in the contracts directory, create a new file, e.g., Allowlist.sol:

2

Writing the Smart Contract

After creating the contract file and having an understanding of the essential components of an NFT allowlist, let's proceed to write the contract structure and implement the allowlist logic:

3

Code Explanation

Imports: Three contracts are imported from the OpenZeppelin library:

  • ERC721Enumerable: This provides the basic functions to manage and enumerate NFTs.

  • Counters: This utility library manages incremental token counters safely.

  • Ownable: provides basic authorization control functions, simplifying the implementation of user permissions. For example, only the owner of a particular project should be able to perform some activities on the platform.

3.1

Contract Declaration & Variables: Here, we declare the contract and indicate it inherits from ERC721Enumerable and Ownable contracts.

Inside, we:

  • Use the Counters library for managing the _tokenIdCounter.

  • Declare _tokenIdCounter to keep track of the latest token ID.

  • Create an _allowlist mapping to manage which addresses are allowed to mint.

  • Have a claimed mapping to ensure an allowed address can't mint NFT more than once.

3.2

Constructor: This is the contract's constructor. When the contract is deployed, this function is run first and once to set the NFT's name to "AllowlistNFT" and its symbol to "ANFT.”

3.3

addUserToAllowlist(): This function allows only the contract owner to add an address to the allowlist, enabling them to mint NFTs.

3.4

blacklistUser(): The contract owner can use this function to remove an address from the allowlist, preventing them from minting.

3.5

mint(): Any user can call this function to mint an NFT, but there are conditions:

  • The caller must be on the allowlist.

  • The caller must not have minted an NFT before (ensured by the claimed mapping).

3.6

IsAllowed(): This function can check if a particular address is on the allowlist.

This contract sets up a basic NFT allowlist system where only certain allowlisted addresses can mint an NFT, and they can only mint once. The contract owner can also manage who's on the allowlist.

4

Compiling the Contract

Now that the contract is ready, it's time to compile it. In the left panel of REMIX, click on the Solidity Compiler icon. Click the Compile Allowlist.sol button. You can also turn on Auto compile on Remix to automatically compile your contracts as you are writing them. Only the solidity icon on Remix shows a green checkmark ✅, your contract has been successfully compiled.

5

Deploying on Local Environment

The next step after contract compilation is to deploy the contract. Click on the Deploy & Run Transactions tab in the left panel. Under Environment, choose the REMIX VM(Shangai) for testing. Deploy the contract by selecting it and clicking Deploy.

6

Interaction

After deploying locally, the contract will appear under Deployed Contracts. Click on the contract, and you'll see a list of functions you can interact with. Use the addToAllowlist function to add addresses you wish to approve to mint NFT, then try the mint function with both allowlisted and non-allowlisted addresses to see it in action.

6.1

In the Remix terminal, you'll find a record of all transactions, whether they succeeded or failed. This makes it convenient for you to identify and troubleshoot any errors during your testing.

7

Deploying to a Testnet or Mainnet

If you're satisfied with the testing, you can choose a different Environment in the Deploy & Run Transactions tab to deploy to either testnet or mainnet, using MetaMask. Ensure you have some Ether for gas fees. Here, I would be deploying on the Sepolia testnet network. You can request a faucet here if you don’t have enough.

Once your contract is deployed on the blockchain, you can proceed to develop a user interface for it. This guide provides a basic framework for an allowlist NFT smart contract. Depending on your specific needs, you can incorporate additional features or tailor the contract accordingly. It's also beneficial to explore protocols that use NFT allowlists to gain insights into how they've implemented their own allowlists. This will provide a deeper understanding of the potential features that can be integrated. Always prioritize comprehensive testing and security audits for your smart contracts before deploying them on the mainnet to ensure both security and functionality.

Covalent’s NFT Ownership & Token Gating Endpoints

Now that your Allowlist NFT is deployed on the blockchain, you can use Covalent's NFT Ownership and Token Gating Endpoints.

Check ownership in NFT collection

GET/v1/{chainName}/address/{walletAddress}/collection/{collectionContract}/

Commonly used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.

Check ownership in NFT collection for specific token

GET/v1/{chainName}/address/{walletAddress}/collection/{collectionContract}/token/{tokenId}/

Commonly used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.

These endpoints confirm ownership within a specific NFT collection, encompassing both ERC-721 and ERC-1155 tokens. You can also verify ownership of a particular token within the collection (ERC-721 or ERC-1155). For further details, you can refer to this link.

Future Roadmap

In the future, the potential roadmap for allowlist contracts is quite exciting. These contracts could evolve to filter users based on more sophisticated criteria, such as the number of NFTs they own, their cryptocurrency holdings, or even their social media activity. This advanced filtering would ensure that only the most qualified users are included on the allowlist.

Moreover, the adaptability of allowlist contracts to multiple blockchains could be a game-changer. This would expand the reach of NFT projects, enabling them to connect with a broader audience and simplify user participation in allowlists.

These are just a few potential enhancements or evolutions of NFT allowlist contracts. As the NFT space continues to grow and evolve, we can expect to see even more innovative and sophisticated allowlist solutions being developed.

Here's a trend in the decentralized space that might influence future developments of NFT allowlists:

  • DAOs: DAOs are decentralized autonomous organizations that are governed by their members. DAOs are becoming increasingly popular in the space, and they could be used to manage NFT allowlists. This would allow NFT projects to decentralize the allowlist process and give more control to their DAO members.

Conclusion

This tutorial has covered the basics of NFT Allowlists, from their importance in the NFT ecosystem to the steps for creating a smart contract and making use of Covalent’s endpoints to verify ownership of tokens. Continue to explore the possibilities of different Allowlist types and stay tuned for future developments, especially the potential influence of DAOs in this space.

References