Bulk mint | erc 721

I want to mint 100 erc 721 tokens in a single transaction. For that, I wrote code in the following way. Is it the correct way? will it make any potential problem?

    function mint(address creator, string[] memory tokenURI) public returns (bool) {
        require(msg.sender == owner,"only permitted for owner");
        for(uint i = 1 ; i <= 100; i++) {
            _safeMint(creator, i);
            _setTokenURI(i, tokenURI[i]);
        }
        return true;
    }

Please recommend If you have any idea for bulk minting in ERC 721

There's nothing wrong with the function you proposed above, though I might suggest making the size of the loop an input parameter like this:

    function mint(address creator, string[] memory tokenURI, uint batchSize) public returns (bool) {
        require(msg.sender == owner,"only permitted for owner");
        for(uint i = 1 ; i <= batchSize; i++) {
            _safeMint(creator, i);
            _setTokenURI(i, tokenURI[i]);
        }
        return true;
    }

This would give you the freedom to choose the amount you want to mint at the time of the transaction and can help avoid situations where you hit the gas limit for a single transaction which can happen if your tokenURIs are long and you run out of gas before you get to a full 100.

2 Likes

Would you recommend ERC 721 to bulk mint if I have the following requirements:

  1. Bulk mint 25 000 nonfungible tokens (or some large number)
  2. I will need bulk transfer mint
  3. I will need to add meta data to NFTs.

Thanks :slight_smile:

1 Like

In my opinion if you are trying to create tens of thousands of NFTs, you might want to consider a Merkle Drop approach. Merkle drops are highly scalable and will offload the gas cost to the recipients plus you will not have to worry about hitting the transaction gas limit.

The OZ team has a good video here.

2 Likes

Did you find any resources to accomplish this? I am in the same place, where I want to bulk mint ~20k NFTs in one transaction. The Merkle Drop approach mentioned is awesome, but it does not fit my use case.