I have implemented a contract where a set of ERC721 tokens should be generated with a function call in private net. Code as follows :

function mint(
    address _owner,
    uint256[] _id
    returns (uint256)
    for(uint i = 0; i<_id.length; i++){
        super._mint(_owner, _id[i]);

It creates up to 33 ERC721 Tokens, then the gas hits the gasLimit and loop ends. I am running it on my private net with genesis file as follows:

  "config": {
  "chainId": PrivateNetworkID,
 "homesteadBlock": 0,
  "eip155Block": 0,
  "eip158Block": 0
"alloc": {
"0x0000000000000000000000000000000000000001": {"balance": "111111111"},
"0x0000000000000000000000000000000000000002": {"balance": "222222222"}
"coinbase"   : "0x0000000000000000000000000000000000000001",
"difficulty" : "0x20000",
"extraData"  : "",
"gasLimit"   : "0x8880000",
"nonce"      : "0x0000000000000042",
"mixhash"    : 
"parentHash" : 
"timestamp"  : "0x00"

JS :

MyNFToken.deployed().then(function (instance) {

 //randomtoken - Array containing 33 tokenID
  return instance.mint(account, randomtoken, { from: account, gas: 4600000 }).then(function (result) {

    console.log('Result = ' + JSON.stringify(result));


In js if I change the gas:4600000 to a higher value, gaslimit exceeds error occurs.

How can I resolve this?Is it possible to create at least 1000 tokens in a function call? Help will be appreciated :)

  • Please explain your use case. Will you be doing this one time or periodically? – William Entriken Jan 25 '19 at 15:05
  • Need more information: How much gas is each create token loop call consuming and what is the gas limit on the network you are on? Assuming you're on Ethereum mainnet the gas limit is 8000000. That would mean your 33 calls are using roughly 240K in gas each. You would hit the gas limit and get the out of gas error message. – Michael Quale Jan 25 '19 at 15:37
  • Thanks...I have added the genesis file above.I tried --targetgaslimit '9000000000000' on the command initiating private net node, but still I'm getting exceeds gaslimit error – angelmaria Jan 28 '19 at 7:21
  • Loops are bound to fail on Ethereum due to gas limits and transaction timeouts. If you want check out cargo.build. You can mint 2^255 ERC-721 tokens at once. – pizzarob Sep 23 '19 at 22:19

As of today 2019-01-25 in mainnet the block gas limit is 8M. If minting a single token consumes 50K gas then you can at most create 160 tokens.

 8000000 / 50000 = 160

If you have to mint 1000 tokens I'd suggest to try a different approach. For example you can store only the root of the merkle tree of the new tokens. If someone wants to redeem tokens they submit the path of the token in the merkle tree, and after validation the tokens is added to their account.


This technique was presented on stage at NFT.nft by yours truly using a combination of ERC-721, ERC-998 (ish) and ERC-1167.

Also the technique is explained in Su Squares at https://github.com/su-squares/ethereum-contract

It is surely too much code to paste in this answer so I'll summarize:

  • You can only create N tokens at once efficiently during contract creation
  • Don't be afraid of creating contracts to create tokens
  • Contracts can be created efficiently using the proxy standard

The presentation is available at http://nft.life

  • Hi - by any chance, were any files/links removed from your net.life website? Cause I didn't find any actual code samples about batch minting. Same for the GitHub repo. I'm specifically talking about the actual code that does the actual MINTING of these 10,000 su-squares. I'm pretty sure l looked through every single folder there (nice project by the way!) So where/how is this batch minting actually happening? – Mark55 Sep 18 '20 at 20:12
  • Thank you. It's in the initialize function. – William Entriken Sep 20 '20 at 1:50
  • Are you talking about the constructor function in SuNFT.sol? Cause while I see 3 different for loops in there - all iterating up to TOTAL_SUPPLY, they're all commented out. So I can't tell if or which of them was ever executed. Also, none of these for loops have a call to the mint function in them, so I'm further confused. Where's the minting happening? – Mark55 Sep 20 '20 at 18:35
  • The for loops are commented out because they would use O(N) gas and they produce the same effect as the latter line of code which runs in O(1). – William Entriken Oct 1 '20 at 17:42
  • 1
    Ah yes, Clients! Of course 😎 I wasn't knocking your approach by the way, on the contrary, I actually LOVE your SuNFT Contract. It’s kinda mind-blowingly refreshing. See, I’ve gotten so used to working with/from OpenZeppelin’s ERC721 Contract - particularly their _mint() and setTokenURI() functions, I’ve forgotten theirs is NOT the only way to implement the IERC721 Interface (which doesn’t even require writing mint() and setTokenURI()!). Your SuNFT reminded me there are other ways to make a compliant ERC721 contract so it's been particularly sobering & inspiring! – Mark55 Nov 16 '20 at 1:38

Guess the problem got resolved :). I changed gaslimit : '9000000000000' in the genesis file. Doesn't know whether it is the correct way of doing it. Though it take a bit ether, tokens are created in bulk amount. Since it is a private net, consuming ether is not an issue.

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.