I am deploying my contract using web3 by taking values (just copy paste) from Etherscan (i.e. abi, contract creation code, etc.) and then deploy my contract on Ganache (gui). When i run the my code through node deploy.js following error displayed (However, on Ganache GUI, that command shows that my contract has been deployed and also shows its address).

Here is my code:

 async function deployWithCreationCode(){

     var contract = new web3.eth.Contract(abi);
    var dc = await contract.deploy({data: crCode})
              from: account1,
              gas: 6721975, // i cannot assign more gas above gas limit of ganache... is it possible to increase this limit.... ?
              gasPrice: '30000000'
return dc._address;


Here is my error:

UnhandledPromiseRejectionWarning: Error: Returned error: VM Exception while processing transaction: out of gas

Note: If size of my contract creation code is less, then no error at all.

1 Answer 1


I cannot assign more gas above gas limit of ganache... is it possible to increase this limit.... ?

Yes, start Ganache with --gasLimit=someHigherValue.

That being said, note that 6721975 is already by itself a pretty high value for a single transaction, so your deployment most likely fails for a different reason ("out of gas" is unfortunately quite a misleading error-message, but I think that Web3.js dev team are aware of that and are working towards fixing it in a future release).

In order to check whether or not your gas value is the problem here, replace this:

send({from: account1, gas: 6721975, gasPrice: '30000000');

With this:

estimateGas({from: account1);

And then make sure that it completes successfully.

If it does, then your gas value is indeed the problem, and you should replace it with whatever the call to estimateGas has returned.

Otherwise, your transaction reverts for a different reason, most likely related to the contract function itself (i.e., your contract's constructor).

One more thing to notice (which I recently encountered myself and took a lot of effort in figuring out):

Ethereum has a contract code-size limit of 24KB.

If you contract's code-size exceeds this limit, then no matter what you do - whether it's in your contract code or in your deployment code - the contract deployment will fail.

How to check your contract's code-size:

  1. If you're compiling via solc executable, then make sure that the size of the output bin file does not exceed 48KB
  2. If you're compiling via solc.js (for example, via Truffle), then make sure that the size of the bytecode field in the output json file does not exceed 48KB

Why 48KB?

2 hexdecimal characters = 2 bytes in the text file = 1 byte in the actual bytecode.

  • if i replaced as you suggested, then i could not deploy any contract... previously i can deploy my contract ... i think if i make transaction like this .... var dc = await contract.deploy({data: crCode}) .estimateGas({from: account1});' it should be wrong... (can you give me complete transaction ... ?
    – Amir Ali
    Nov 21, 2019 at 11:11
  • @AmirAli: Sorry, but I don't understand "then i could not deploy any contract". I explained that you should replace send with estimateGas in order to investigate whether or not your problem is indeed gas-related. Of course you cannot deploy your contract with estimateGas, but this was not the purpose to begin with. Did you read my answer carefully enough? Nov 21, 2019 at 11:19
  • sorry i understand now. so, there is now no error... and it complete all my transaction...
    – Amir Ali
    Nov 21, 2019 at 11:23
  • @AmirAli: Did estimateGas complete without reverting? Like I said, if it does, then your problem is indeed gas-limit, and you should simply take whatever estimateGas returns and use it instead of your current value. Is this indeed the case? Nov 21, 2019 at 11:25
  • yes, without revert it... thanks ... i will try then
    – Amir Ali
    Nov 21, 2019 at 11:26

Your Answer

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

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