Hi there, wondering what the best approach of mining 10000 or more NFTs is? I’ve come up a few approaches listed below:
1). A single function mint() with no for loop inside with which only 1 NFT can be minted each time the function is called. The function will be called 10000 times;
2). A single function batchMint() with a for loop inside with which up to 100 NFTs can be minted each time. The function will be called 100 times;
3). A single function batchMint() with a for loop inside with which all 10000 NFTs can be minted in one call. The function will be called just once.
I suppose 3) will easily reach block gas limit and 1) will cost too much effort and time. 2) seems to be fine, but not sure if it is golden.
Therefore, I’m wondering if there is a standard approach for doing this. Thanks.
Hey @marsxr, thanks for the reply. How you did it looks very intuitive to me.
One of the motivating examples for me to ask this question is HashMask. They minted over 16,000 NFTs across a long array of transactions, most of which have fewer than 40 NFTs minted in each one. That is then roughly 400 transactions over multiple days. I don’t know how they did it, but they didn’t look like being programmatically generated.
function mintNFT(uint256 numberOfNfts) public payable {
require(totalSupply() < MAX_NFT_SUPPLY, "Sale has already ended");
require(numberOfNfts > 0, "numberOfNfts cannot be 0");
require(numberOfNfts <= 20, "You may not buy more than 20 NFTs at once");
require(totalSupply().add(numberOfNfts) <= MAX_NFT_SUPPLY, "Exceeds MAX_NFT_SUPPLY");
require(getNFTPrice().mul(numberOfNfts) == msg.value, "Ether value sent is not correct");
for (uint i = 0; i < numberOfNfts; i++) {
uint mintIndex = totalSupply();
if (block.timestamp < REVEAL_TIMESTAMP) {
_mintedBeforeReveal[mintIndex] = true;
}
_safeMint(msg.sender, mintIndex);
}
/**
* Source of randomness. Theoretical miner withhold manipulation possible but should be sufficient in a pragmatic sense
*/
if (startingIndexBlock == 0 && (totalSupply() == MAX_NFT_SUPPLY || block.timestamp >= REVEAL_TIMESTAMP)) {
startingIndexBlock = block.number;
}
}
sorry for the noob question - I assume that batch minting will have the lowest fees here but there will still be a gas price for each NFT that is minted regardless so you are just minimizing the costs of running the contract ?
Batch minting just lowers the cost per mint. Alternatively you could allow users to mint (and hence pay the cost of minting), either by buying a token (such as through a sale contract) or where the contract was setup to allow them to mint (such as a Merkle Proof)
Hi @abcoathup, to have a contract setup to allow people to mint using a Merkle Proof is something new to me. Wondering if you could be more specific about this?