6

Using Solidity Browser ( https://ethereum.github.io/browser-solidity/ ) to mine a contract on testnet with injected web3 and metamask account, throws this error:

callback contain no result Gas required exceeds limit: 3000000

This contract ( source code => https://gist.github.com/computerphysicslab/f362383f9d3fed26becba48b934bbcfc ) is expected to cost around 6 million gas to deploy (according to JS VM environment). Nevertheless when trying to increase the gas limit these errors are thrown:

callback contain no result Gas required exceeds limit: 4000000
callback contain no result Gas required exceeds block gas limit: 5000000
callback contain no result Gas required exceeds block gas limit: 6000000
callback contain no result Gas required exceeds block gas limit: 10000000
...

So, it seems like it is not possible to mine the contract becasue there is a block gas limit around 5 million gas. Is it possible to overcome this limit somehow?

Refs.:

Solidity browser compiler crashes

why the browser based solidity compiler crushes when the code is too long?

Exceeds gas block limit error when deploying near block gas limit contract

3
+50

Unless the miners increase the block gas limit your only option is to split the contract into several contracts.

So each contract has its own address, and you can make calls between them. For example an ICO Crowdsale can be split into:

  • Crowdsale: Manage the crowdsale, how tokens are allocated, rewards, opening, closing
  • Token: Implements ERC20, can create tokens, approve transfer
  • Wallet: Manage funds received during the crowdsale

Also splitting helps a security audit since each contract has a limited scope.

Each contract can be deployed indepedently, and through a configuration method you complete the setup.

  • I tried it, but splitting the contract using include commands does not reduce the total gas cost of deployment. – Juan Ignacio Pérez Sacristán Jun 28 '17 at 14:56
  • 1
    Using include does not split the contract. That is just an instruction to the compiler to put all of those things together into one contract. – Jeff Coleman Jun 28 '17 at 15:58
  • @JuanIgnacioPérezSacristán I've updated with an example – Ismael Jun 28 '17 at 18:00
  • 1
    @JuanIgnacioPérezSacristán Inheritance will pull all the code together. You have to split into separate contracts so each can be deployed independently. Look at status ico github.com/status-im/status-network-token, they have separate contracts and a script that will deploy them, and set the initial configuration. They use truffle, that make really easy to deploy several contracts, and configure them. – Ismael Jun 28 '17 at 22:26
  • 1
    Sometimes make for sense to use libraries if the code can be reused, like in SafeMath for example. Because libraries use the same shared data. If the contracts are separated then they can only access the data through the public methods. – Ismael Jun 28 '17 at 22:29
6

Actually the maximum gas per transaction is given by eth.getBlock('latest').gasLimit which is around 4.7million today.

Edit : Gas limit is increasing and it seems the target is to reach a limit of 6.7million so without to do anything you might soon be able to deploy your contract. Source: Reddit

In order to deploy your contract you have to reduce the cost of deployment.

There is ways to reduce gas cost:

  1. Simplify the contract. (especially constructors)
  2. Use the optimizer
  3. Split it into multiple contracts.
  4. Refactor to use libraries

You can for example try to use SafeMath instead of your own implementation of it.

Or even though you might have done it but you can remove part used to debug like

// @notice For debugging purposes when using solidity online browser
function whoAmI() constant returns (address) {
    return msg.sender;
}

By the way the discussion to increase gas limit are on the way, some miner pools already increased it but some huge one are still using this "old" limit used to prevent DDOS attacks. This thread on Reddit explains a bit the current issue with gas limit.

  • Very helpful tips. My code is already splitted into several contracts, but still requires too much gas to deploy. – Juan Ignacio Pérez Sacristán Jun 28 '17 at 21:17
  • 1
    I edited my answer. Gas limit is increasing and it seems target is to reach 6.7M. Enough to deploy your contract. I hope for you in a few hours/days you'll be able to do it without touching your contract – Crema Jun 29 '17 at 12:05
  • 1
    Hello again :) We reached more than 6M for the gas limit, can you try to deploy the contract again? – Crema Jun 29 '17 at 17:44
2

You will need to put some of the things, like safemath, into a library contract, which you can deploy as separate contracts. Else there is no way for you to shrink the gas costs.

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.