I know this issue was discussed before several times, but I cant get the solution to my problem from any of the answers,

My contract got deployed fine before adding the following function,

function setApproval(address addr, bool approved)payable returns(string, uint, uint) {

       //some logical operations and assignments


as soon as I add the function and try to deploy the contract, I got this error

Error encountered, bailing. Network state unknown. Review successful transactions manually. Error: The contract code couldn't be stored, please check your gas amount.

test rpc server shows following logs

Transaction: 0xd5791ac0c6059cbd43e00a7fabe566ada3f0572966f12ff25da6e04215840f39 Contract created: 0x9062592c5dd06340401c1e750ddb025defabf5be Gas usage: 4712388 Block Number: 16 Block Time: Sat Jul 22 2017 03:30:30 GMT+0530 (India Standard Time) Runtime Error: out of gas

again after removing this function contract deployed without errors

what is wrong with this function?

My contract code is around 250 lines, is there any limit on contract code size??

Thanks in advance

  • 1
    How are you deploying the contract? Try to increase the gasLimit setting, if any.
    – jeff
    Commented Jul 21, 2017 at 23:48
  • 1
    How are you deploying your contract? If you put your code we can help you with a modified version. To modify the gas amount for a single transaction you do something like this eth.sendTransaction(params...., { gas: 10000000 }).
    – Ismael
    Commented Jul 22, 2017 at 1:54
  • @jeff I am deploying the code using truffle console, Is it possible to increase the gas limit in Azure Ethereum Consortium Blockchain Commented Jul 23, 2017 at 1:46
  • @Ismael I am getting the error while deploying contract, Its not about single transaction, the contract without setApproval() funnction is getting deployed without any error and I can call the functions with the method you have suggested, but as soon as I add this particular function and try to redeploy the contract I get the error message which I have specified in the question Commented Jul 23, 2017 at 1:52
  • 1
    @pabloruiz55 code inside the setApproval () doesn't affect the result I have tried commenting the code, finally after reading some articles I came to assumption that the size of code is limited in Azure ethereum consortium blockchain, as the max. gas limit for a block is 4712388. Commented Oct 23, 2017 at 12:43

5 Answers 5


In your 2_deploy_contracts.js file, change the gas price defaults to a higher number, i.e.:

// 2_deploy_contracts.js

const MyContract = artifacts.require('./MyContract.sol')

module.exports = function (deployer) {
  deployer.deploy(MyContract, { gas: 5000000 })

I had the same issue and this worked for me.

  • this works with testrpc, I have tried using this with Azure etherum consortium blockchain network, its doesn't work, finally after reading some articles I came to the assumption that the size of code is limited in Azure ethereum consortium blockchain, as the max. gas limit for a block is 4712388. I believe this is the limitation of Azure ethereum consortium blockchain. Commented Oct 23, 2017 at 12:46
  • @SwapnilKumbhar, I'm using also Azure Ethereum Consortium Blockchain network and encounter this error when I try to deploy a contract throw my dApp. But it works well for the same contract if I deploy it throw Remix. I don't know what's my problem, but it seems something with the process of deploy and not the contract size or gas required
    – dchang
    Commented Jan 24, 2019 at 18:12
  • @dchang Can you share your contract code here? that will be helpful to debug your issue, For Now I will suggest try to reduce Lines Of Code and try to deploy. Better try removing some heavy function, If it works then logically divide your contract in to multiple contracts and deploy them individually, I have applied this solution when I faced the issue with some large contracts. Commented Jan 25, 2019 at 6:47
  • @SwapnilKumbhar As already stated, the problem it's not the contract it self, as I can deploy with remix. And to discard it I'm trying with a very simple contract: "pragma solidity ^0.5.3; contract TestContrato{ }". You can't have simpler than that. Additional note: I'm not using truffle, instead I'm trying to user only web3 (version 1.0.0-beta.36), using deploy() method or sending a raw transfer with data: bytecode
    – dchang
    Commented Jan 28, 2019 at 10:51

When a contract inherits from interface and doesn't implement a function this error will be issued.

Truffle 4.0.4 solc 0.4.18

interface IF { 
    function doSomething() external view returns(uint); 

contract Inherit is IF {
    Inherit() public; 

when deployed. will issue error:

The contract code couldn't be stored, please check your gas amount

solution is to implement the function.

contract Inherit is IF {
    doSomething() external view returns(uint) {
        return 5;

The problem which happens rarely but causes exactly the same error message is the following:

Currently, contract code size is limited to 24KB, and sometimes, your bytecode can be greater than it, which will cause the exact same issue.

Go to your contract build json file, and check if the deployed bytecode size is greater than 24Kb.

Solution: This can be solved by various contract optimizations such as removing sufficient getters, public declarations, etc.


I have used @rhlsthrm solution with extra modification because his solution gave me

Error: exceeds block gas limit

My solution is for Geth.

First, get gas limit from latest block



copy the gas limit and then paste it like this

var Identity = artifacts.require("./Identity.sol");

module.exports = function(deployer) {
  deployer.deploy(Identity, { gas: 794722 });

increase gas value in you deploy file.

if you log the deploy error, you can see gas detail, like this :

cumulativeGasUsed: 1217170,
effectiveGasPrice: 2500000011,
gasUsed: 1000000,

please check if the 'gasUsed' is smaller than 'cumulativeGasUsed' so you shall increase gas value in you deploy code setting, like this :

const result = await new web3.eth.Contract(abi)
      data: evm.bytecode.object,
    .send({ from: accounts[0], gas: 1000000 });

change gas value (1000000) to (2000000) like this :

const result = await new web3.eth.Contract(abi)
      data: evm.bytecode.object,
    .send({ from: accounts[0], gas: 2000000 });

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.