How to airdrop NFTs to specific NFT owners?

391 views Asked by At

I want to understand how can we give free ERC721 or ERC20 tokens to specific NFT owner addresses. For example Bored Ape yacht club created an ERC20 coin with a pre-defined amount which can be claimed only from the owners of the BAYC NFTs. I tried to find out an answer in their smart contracts, but I couldn't find their ERC20 coin contract therefore I can't figure out how the restrict the distribution of coins.

In my project I want to create 2 ERC721 smart contracts and all owners of NFTs from the first contract should be able to mint for free NFTs from the second smart contract. If you are an owner of an NFT from smart contract 1 you can claim free NFT from smart contract 2. Can you provide me with some resources or ideas where I can learn how to achieve that

2

There are 2 answers

0
glinda93 On BEST ANSWER

You can, in the second smart contract, check whether the caller of the mint function is a token holder of the first smart contract or not.

function mint() external {
  require(IERC721(_firstToken).balanceOf(msg.sender) > 0, 'should be a holder of the first token');

  _mint();
}

You can import ERC721 interface from openzeppelin library, or just cut&paste from EIP-721.

0
Igor Senych On

There must be some restrictions on how many nftTwo tokens can be minted per single nftOne token. Otherwise, you will be exploited and users will be able to mint an unlimited amount of nftTwo tokens.

IERC721 public nftOne;
uint public nftTwoMaxMintCount;
mapping(uint => uint) public nftTwoMints;

function mintNftTwo(uint nftOneTokenId) external {

    // Only the owner of nftOne token can execute mint
    require(msg.sender == nftOne.ownerOf(nftOneTokenId), "not the owner of nftOne token");

    // The number of allowed nftTwo token mints is limited by nftTwoMaxMintCount 
    require(nftTwoMints[nftOneTokenId] <= nftTwoMaxMintCount, "nftTwo token mints overflow");

    // Increment the number of minted nftTwo tokens per nftOne token id
    nftTwoMints[nftOneTokenId] += 1;

    // Execute mint
    _mintNftTwo(); 

}

Please check OpenZeppelin's implementation of the ERC721 and read their docs for more details.