1

I'm looking to mint around 100 NFTs (or more if possible) in the constructor of my smart-contract.

• During deployment I'm passing in an array of 100 ETH addresses to the constructor, which then uses a for loop to iterate through that array, minting one NFT to the current address from the Array, at each iteration. (This minting is happening by calling the standard _safeMint() function from OpenZeppelin's ERC721 contract -- I'm using their contracts & libraries for this project.)

• I tried running all this on localhost and its working great thus far - and I'll definitely be testing it on Ropsten and/or Goerli next. But of course we all know things can vary greatly when it comes to deploying on mainnet.

So what I'd like to figure out is the following:

  1. What's the best way to estimate the actual COST of deploying this contract - and minting those 100 NFTs on mainnet?
  2. Is minting 100 NFTs in the constructor even possible - or is that already too much? Or, conversely, is 100 perfectly fine and I can actually push it to say 300, or even 500?

By the way, we do realize this isn't going to be cheap, but we're willing to take the hit, so it's really more about just what's technically possible in terms of block size - and what's not.


NOTE: I do also plan to have an additional stand-alone batchMint() function in the contract that'll let us mint like say 30 NFTs at a time, again using a for loop to call _safeMint() - just so we have this as a backup.
In other words, if it turns out that we need to Mint a total of say 300 NFTs, but the Constructor can only handle minting 75 NFTs upon deployment, we'll then have the ability to manually call our batchMint() function a bunch of times until we've finished minting all the NFTs the project needs.

But even here, we need to figure out what the limit is on how many NFTs can be minted in one for loop each time we call our batchMint() function.

4
  • 100 is small enough that you can probably complete this transaction all at once, for millions of gas. If you need to do more that 100 all at once, especially during contract deployment, we have a trick for that which is cheaper, but is more complicated. It is a code storage conduit. Aug 14, 2022 at 9:50
  • "we have a trick"? .... OK, what's the "trick"? (and who's "we"?) This is supposed to be about helping one another, not red-herring-ing :-)
    – Mark55
    Aug 15, 2022 at 17:20
  • That's the trick, the data is stored in the contract's code. Here's one I saw etherscan.io/tx/…. This question is only doing 100, so not worth it to do code-storage approach. I host NFT Community Service Hour weekly to go through technical things like this, if you're interested. Can say much more than this comment box. Aug 19, 2022 at 12:46
  • 1
    ok I looked at that tx you posted a link for - unfortunately that contract isn't verified - there's no code to look at, so we're back to - or still at square Zero. Interesting (or maybe kinda crazy) that people are interacting with that contract when it hasn't even been verified... Anyway, I'll try to check out your weekly hour talk. Thanks!
    – Mark55
    Aug 20, 2022 at 15:42

1 Answer 1

1

Cost is gas * gasPrice.

You can test offline with JavaScript EVMs, or on a testnet, and the gas consumption of your experiments should be consistent.

The gasPrice you pay is established when you deploy the contract. It fluctuates with market conditions and the priority you want to assign to the transaction. It affects the "cost" of the deployment and you can, of course, delay your deployment if the network is congested and the cost is too high. https://www.ethgasstation.info/ can give you an idea of an estimate.

The block gasLimit is a hard cap on the amount of gas your transaction can burn. Beyond this, it will simply fail (at any price). Have a look over here to see what this value is. It also fluctuates.

Since you recognize the need for a bulkMint() function outside of the constructor, I would consider relying exclusively on that to avoid duplication in the code.

Hope it helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.