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 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 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 at 7:21

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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