[Ethereum] The contract code couldn’t be stored, please check your gas amount

contract-debuggingcontract-deploymentcontract-designcontract-developmentsolidity

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

Best Answer

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.

Related Topic