Solidity – Block Gas Limit Exceeded When Compiling Contract in Solidity Browser

blockscontract-deploymentgasmetamasksolidity

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

Best Answer

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.