简体   繁体   中英

How to airdrop NFTs to specific NFT owners?

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

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM