1

I have declared a function in my solidity code that is responsible for minting NFTs. However, Does anyone know how could I be able to mint a couple of NFTs in a single transaction with _safeMint() function inheriting from the ERC721?

Furthermore, If anyone makes me aware of the difference between _safeMint() and _mint(), I would appreciate it.

Here is my function and for loop; enter image description here enter image description here

5
  • you can't mint big number of nfts in 1 transaction.. at some point the transaction will be too big maybe bigger than a block
    – Majd TL
    Oct 13 at 11:23
  • Could you please tell me why is that?? Or direct me to a valuable article Oct 13 at 12:15
  • @SinaRahimi you should have a look at the gas concept before developping smart contracts. Oct 13 at 12:52
  • when u mint nft you write data in the blockchain and that cost u Gas (a lot of gas). Each generated block has a max gas limit.. at some point the amount of gas u use will be bigger that the max gas limit of the block.
    – Majd TL
    Oct 13 at 13:37
  • "Big" is relative, I've added some notes about that as an answer with specific (round estimate) numbers Oct 13 at 14:15
1

In one transaction:

To mint one item, use _mint(...).

To mint up to 20 items, use _mint(...) in a for-loop.

To mint up to 500 items, use the "ghost minting" technique. Please see the Area NFT contract for an open source example of that. Note this is an advanced technique that will surely require customization based on your application.

To mint enough tokens to track ownership of nanobots a few micron in size and in aggregate totaling half the size of Earth, use the "lazy array" technique. Please see the Su Squares contract for an open source example of that. This is only possible at the time of contract deployment.

enter image description here


The _safeMint(...) function makes the recipient of a token, if it's a contract, get a onERC721Received(...) call. This functionality is not required by the standard and you may have some specific reason you want to use that.

1
  • Thanks for your information. I am importing OpenZeppelin ERC721 in my solidity codes on Remix, and whenever I try to mint more than one NFT at a time, the site goes down. Has this happened ever to you ever? Oct 13 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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