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

Created on 28 Feb 2018  路  20Comments  路  Source: trufflesuite/truffle

New issue :)
This exemple:
http://truffleframework.com/tutorials/robust-smart-contracts-with-openzeppelin
No --testnet flag.

/home/testnet/go-ethereum-1.7.3/build/bin/geth --rpc --port 30304 --rpcport 8599 --networkid 3 --rpcapi db,eth,web3,net,admin,miner,personal --cache 1024 --maxpeers 25 --datadir /home/testnet/.ethereum --keystore /home/testnet/.ethereum/keystore --nousb --mine --minerthreads 1 --unlock 0xC1320531dF2612B85e6FEDFd4d6358ed711bbe66 --password /home/testnet/pass

cat genesis.json

{
  "config": {
    "chainId": 3,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "nonce": "0x0000000000000033",
  "timestamp": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x8000000",
  "difficulty": "0x100",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x3333333333333333333333333333333333333333",
  "alloc": {}
}

cat truffle.js

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8599,
      network_id: 3,
      from: "0xC1320531dF2612B85e6FEDFd4d6358ed711bbe66",
      gas: 1000000,
      gasPrice: 10000000000,
    }
  }
};

result:

testnet@e3:~/oz-workspace$ truffle compile
testnet@e3:~/oz-workspace$ truffle migrate
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0x2281a6116824b0941b5b12c6086d0845bdfd8be82873f2c32ee05ca6f88a0e35
  Migrations: 0x2092eb6cc176d5313335fd2adb06af98473d0d51
Saving successful migration to network...
  ... 0x779632747cd77cde0461e1e6bd442d5882d12450fe552227e9c96561403326ed
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying TutorialToken...
  ... 0x2eb61ab6893bbafea70a43a96dde844751279356ad49aad468f6e5f10808f582
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.
    at Object.callback (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/contract.js:147:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/method.js:142:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:89:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-migrate/index.js:225:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
    at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
    at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)

Whi?
Operating System: Ubuntu 16.04.3 LTS
Truffle v4.0.6 (core: 4.0.6)
Solidity v0.4.19 (solc-js)
Ethereum client: go-ethereum-1.7.3
node version: v9.4.0
npm version: 5.6.0

Most helpful comment

I had this error too and it turns out nothing to do with gas, it's my ERC721 token contract didn't implement the contractor of the ERC721Token correctly...

I flatten the contracts and put it into remix, it did show me the problem.

A correct error should be shown in truffle!

All 20 comments

@freshonline Ok everything looks good as far as I can see. Could you try changing the gas amount in your truffle.js to 2000000 as below?

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8599,
      network_id: 3,
      from: "0xC1320531dF2612B85e6FEDFd4d6358ed711bbe66",
      gas: 2000000,   // <--- Twice as much
      gasPrice: 10000000000,
    }
  }
};

This error message has been a royal pain in my side since I started with truffle a few weeks ago. I've tried increasing the gas to the max, but it only puts off the problem. I've found for instance that a test contract that by rights should be one file has morphed into 6, each following slightly different paths. Even then, I hit a case where nothing I could do could get me to get a single test contract loaded if it included starting a new instance of the contract I was testing. At this point I have two tests, each with certain assertions that make the comment "if the contract was started then this test will fail." If the contract is set up in migration/2_... with one parameter, the test will pass, but a different test will then fail. Gotta be a better way ...

Oh, and did I mention that I already went through Assert.sol to comment out every function I never was using? That stretched what fit in the gas too. But ... ugh!

@fdouglis You might find this gas-reporter helpful. If you write little tests that simulate the deployment sequence, it will print a chart at the end of the run which shows how much each deployment actually cost.

Tests like:

const blockLimit = 7000000;
it('should deploy my system', async function(){
  const system = await SystemInit.new({gas: blockLimit});
  const systemPart = await SystemPart.new(system.address, {gas: blockLimit});
});

Thanks @cgewecke that could be useful. So far all my tests have been in Sol rather than js, but at some point I may move that way. In any case, my issue has been with test/TestXYZ.sol not deploying, whereas I think you are referring here to the gas incurred by pieces of the contract under test?

PS As an aside, I'm not sure I understand the benefit of gitter, or at least the way I see it often used. I threaded discussion on a specific topic, where you can subscribe to notifications on that thread, sure beats the free-for-all flat discussion space of gitter. Yet the template for posting here asks, have you tried to get help on gitter first?

I realize I digress here :)

@fdouglis Apologies I didn't quite grasp your use case when I commented. The original poster is trying to deploy Token contracts to the testnet where the limit is fixed by design. You're trying to run unit tests in solidity. If you're using ganache the client blockLimit can be increased arbitrarily by running it in a separate terminal as follows:

ganache-cli --gasLimit 0xffffffffff   // Some huge amount (10 f's)

and then setting your gas in Truffle.js to slightly less:

networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*",
      gas: 0xfffffffff, // (9 f's)
    }
  }

On the pros and cons of gitter: It seems good for 'how do I do x' questions. People are really helpful. By convention git issues have stricter rules about what can be addressed. They're for feature requests and bug reports that include guides to reproduction. Definitely agree they're more searchable but in turn less 'chatty', more formal.

I have tried the equivalent of what you have said, I thought. In ganache, the GUI, I have the gas limit set to "80000000000" (I note the GUI interface doesn't allow hex numbers, and in truffle.js, the ganache network set to "800000000". (10x less). Nevertheless, I ran into out of gas messages. I tried your approach, converting your hex value to decimal and setting that as the gas limit, then setting truffle.js to 9f's. I ran out of gas again.

Is there any chance that "runtime error: out of gas" is a red herring? For instance, if something reverted deploying the contract, would it consume all the gas and make ganache report out of gas?

As for gitter and threading: I understand your point about keeping the chitchat on github itself down, and that makes sense. I hope the Powers That Be will improve gitter to make it more usable. Right now it's like a CB Radio. (I'm showing my age.)

@fdouglis Out of curiosity could you try at the command line with ganache-cli? Also maybe specify the network name when you run the tests, e.g truffle test --network development for example. All of this can be run in your regular shell rather than truffle develop.

It's possible there's a bug in the UI, I'll check into that.

I ran with a newly installed ganache-cli, with the same options, and with the same bad result. I have been specifying an explicit network all along, be it ganache (GUI), or now ganachecli.

In addition, FYI, I have just checked whether it could be a change from moving to the more recent truffle. But I get the same error with the version I installed a month or so ago, as the one I built and slightly modified this week. (The modifications are to output events unconditionally; I didn't expect my changes to break deployment, but it was possible some other recent change caused it. Apparently not...)

Yes, "gas: 2000000" the solution. Thank you.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x335f8376b2803c21ef8dc7dac74718773e9aec6f29550632d02cb13b5cfdc019
  Migrations: 0xcd4538bf3d2c1aee731a16999e1f822855592b61
Saving successful migration to network...
  ... 0x25043dbc8c7bf5c3781589b54ee510027547bd2af28f81647792aa7094468ef2
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying TutorialToken...
  ... 0x18d50c3b830566e16004f45d0b93608c5ed1edb691e44a0c9466f3799f8edc93
  TutorialToken: 0x2ba9357366d7013c7081a8e3a346182ac38811a1
Saving successful migration to network...
  ... 0xd1dfba5a2d34ef51458f4713b641f9e3362c4e505585bf3f8539ebf10345e948
Saving artifacts...

But I do not see any new transactions in my mist wallet :(

@freshonline It's possible you weren't connected to enough peers to have the transactions picked up by the network. Your node accepted the txs, but I can't find them in the Etherscan Ropsten explorer.

This stackexchange discussion might be helpful.

Congratulations on getting the migrations to work locally at least! Great work. Going to close this since the issue you're having is not Truffle related anymore.

While the original post was resolved by increasing gas, I have to note that I raised a similar problem, specific to truffle (it's the test contract that won't deploy), which is not resolved by increasing gas. It's hard to believe the contract is so huge that no amount of gas will address it. After all, it's deploying that is failing, not running! Should I open a different case for it?

@fdouglis Yes definitely. If you're able to link to a public repo where the bug can be easily reproduced (and suggest reproduction steps) that would be immensely helpful. Additionally, if you could note in the issue title that the context for the bug is Solidity testing, that would also be nice. A lot of people run into this doing conventional migrations, but the testing context is slightly different and we should distinguish between these cases.

Thanks so much!

I will do so, but I can't link to the code, as it's not public. Thanks.

I had this error too and it turns out nothing to do with gas, it's my ERC721 token contract didn't implement the contractor of the ERC721Token correctly...

I flatten the contracts and put it into remix, it did show me the problem.

A correct error should be shown in truffle!

In case someone stumbles upon here.

I was trying to migrate with zeppelinOS:

zos push --network ropsten_infura

This truffle-config.js worked for me:

ropsten_infura: {
      network_id: 3,
      gas: 2000000,
      gasPrice: 32,
      from: '0x123...', // the wallet address
      provider: function() {
        return new HDWalletProvider(process.env.WALLET_MNEMONIC_ROPSTEN, `https://ropsten.infura.io/v3/${process.env.INFURA_API_KEY}`)
      }
    }

In my case, when i deploy upgradeable contract with OpenZeppelin, it return the same issue "The contract code couldn't be stored, please check your gas limit". I recognize that because of different between of gas limit in Genesis file and targetgaslimit in mining, then i set they are same, it works for me

On my case it had to do with some errors on the contract.

It also happened that i had misspelt one of the contract names and the same error was also being yield..

I'm not sure if https://sol-trace.com/ would have helped in this case but definitely something worth having a look in order get better error messages.

Was this page helpful?
0 / 5 - 0 ratings