Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

The contract code couldn't be stored, please check your gas amount during successful deployment #558

Closed
Mc01 opened this issue Sep 5, 2017 · 19 comments

Comments

@Mc01
Copy link

Mc01 commented Sep 5, 2017

Issue

After running truffle migrate for mainnet network i've got:

Running migration: 1_initial_migration.js
  Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.

On etherscan i see:

0xe728474cc7b4bf31749fb6b5f4d377f58afb4a2bf1abe9283b4c03ceb7d8619f | (pending) | 32 secs ago | 0x71544d4d42daab49d9f634940d3164be25ba03cc | OUT | Contract Creation | 0 Ether | (pending)

Transaction completes successfully: https://etherscan.io/tx/0xe728474cc7b4bf31749fb6b5f4d377f58afb4a2bf1abe9283b4c03ceb7d8619f
Contract is created: https://etherscan.io/address/0x1d3d6458065f3cd778541f0676db6837be9252ec

Its regular issue we have with truffle framework...

@charltonh
Copy link

Experienced this issue trying to run truffle test on rinkeby testnet from gentoo linux.

I've discovered that Assert.sol generates an EVM binary that is just too big to be deployed without it choking. I ended up manually editing Assert.sol and taking out a couple of funcs that I wasn't using.

Now the EVM binary is slightly smaller and deploys on rinkeby, and my tests complete successfully.

@tcoulter
Copy link
Contributor

Thanks for the info guys. This is good sleuthing.

@tcoulter tcoulter added the bug label Sep 15, 2017
@dylanseago
Copy link
Contributor

Related: trufflesuite/truffle-migrate#15

@7flash
Copy link

7flash commented Dec 21, 2017

The same issue. That's why I have deployed a lot of pointless Migrations.sol

	config.networks["mainnet"] = {
		provider: new HDWalletProvider(mnemonic, "https://mainnet.infura.io/"+infuraToken),
		network_id: 1,
		gas: 4e6,
		gasPrice: 2e10
	};

@delormemarie240
Copy link

Hello,
Is there any update on this issue ? I have same problem, an it's very annoying -__- I do not find any solution on other forum

@charltonh
Copy link

Try the latest beta release of truffle, or try finding the Assert.sol file in truffle and manually editing it to take out a couple of functions that you don't need.

@7flash
Copy link

7flash commented Dec 23, 2017

@ryanli-me
Copy link

@7flash Hi, I used yarn to download dependencies and I tried your suggestion by changing the line you mentioned in node_submodules/web3 and node_submodules/web3-engine-provider, but still didn't work. The error is either check your gas amount or exceeds 240 seconds. Could you please help? Thanks so much!

@ryanli-me
Copy link

@charltonh Thanks for the info! Could you please specify which functions are not used and safe to delete?

@charltonh
Copy link

@liyihe96 Depends on which functions you are using in your program. I took out just a couple small functions that I knew I'd never use, which amounted to just a few lines. Then the Assert.sol compiled code was able to 'fit' and it deployed successfully.

@7flash
Copy link

7flash commented Jan 13, 2018

@liyihe96 exceeds 240 seconds - Probably you should just raise gas price up to 50 GWei for mainnet.

@max-l
Copy link

max-l commented Jan 30, 2018

Getting the same issue, I have a contract that deploys on Ganache (truffle test),
the contract implements the EIP20Interface, if I declare "contract TTC is EIP20Interface"
in the contract, I get the error.

truffle migrate 
Compiling ./contracts/EIP20Interface.sol...
Compiling ./contracts/TTC.sol...
Writing artifacts to ./build/contracts

Using network 'development'.

Running migration: 2_deploy_contracts.js
  Deploying TTC...
  ... 0x76abb97563016f18eb1eeedeab4ddf3d7da760a7b2669af96a3f1ceabd8224c6
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/cli.bundled.js:328412:46)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:37990:25
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:330356:9
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:176198:11
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:326008:9
    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329052:7)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176427:18)
    at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176717:12)
    at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176872:12)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:176832:24)


@nickjm
Copy link

nickjm commented Jan 30, 2018

In case this applies to any of you, make sure you try deploying any libraries you use separately, then link them to the main contract(s) to limit the gas used in each migration txn.

@max-l
Copy link

max-l commented Jan 31, 2018

@nickjm this is my migration script :

var TTC = artifacts.require("./TTC.sol");
var EIP20Interface = artifacts.require("./EIP20Interface.sol");

module.exports = function(deployer) {
  deployer.deploy(EIP20Interface);
  deployer.link(EIP20Interface, TTC);
  deployer.deploy(TTC);
};

and my contract:


contract TTC is EIP20Interface {
...

The "The contract code couldn't be stored, please check your gas amount." seems to apply to the deployment of EIP20Interface

This is a test settup, where can I increase the gas amount for the store transaction to succeed ?

I am using Ganache and the account doing the deploy starts with 100 ETH, is that not enough, or is the error message about another gas treshold being busted ?

@jbarros35
Copy link

not work for me see my sol file please

pragma solidity ^0.4.21;

/**
* Example script for the Ethereum development walkthrough
*/

contract Wrestling {
/**
* Our wrestlers
*/
address public wrestler1;
address public wrestler2;

bool public wrestler1Played;
bool public wrestler2Played;

uint private wrestler1Deposit;
uint private wrestler2Deposit;

bool public gameFinished; 
address public theWinner;
uint gains;

/**
* The logs that will be emitted in every step of the contract's life cycle
*/
event WrestlingStartsEvent(address wrestler1, address wrestler2);
event EndOfRoundEvent(uint wrestler1Deposit, uint wrestler2Deposit);
event EndOfWrestlingEvent(address winner, uint gains);

/**
* The contract constructor
*/
function Wrestling() public payable {
	wrestler1 = msg.sender;
}

/**
* A second wrestler can register as an opponent
*/
function registerAsAnOpponent() public {
    require(wrestler2 == address(0));

    wrestler2 = msg.sender;

    WrestlingStartsEvent(wrestler1, wrestler2);
}

/**
* Every round a player can put a sum of ether, if one of the player put in twice or 
* more the money (in total) than the other did, the first wins 
*/
function wrestle() public payable {
	require(!gameFinished && (msg.sender == wrestler1 || msg.sender == wrestler2));

	if(msg.sender == wrestler1) {
		require(wrestler1Played == false);
		wrestler1Played = true;
		wrestler1Deposit = wrestler1Deposit + msg.value;
	} else { 
		require(wrestler2Played == false);
		wrestler2Played = true;
		wrestler2Deposit = wrestler2Deposit + msg.value;
	}
	if(wrestler1Played && wrestler2Played) {
		if(wrestler1Deposit >= wrestler2Deposit * 2) {
			endOfGame(wrestler1);
		} else if (wrestler2Deposit >= wrestler1Deposit * 2) {
			endOfGame(wrestler2);
		} else {
            endOfRound();
		}
	}
}

function endOfRound() internal {
	wrestler1Played = false;
	wrestler2Played = false;

	EndOfRoundEvent(wrestler1Deposit, wrestler2Deposit);
}

function endOfGame(address winner) internal {
    gameFinished = true;
    theWinner = winner;

    gains = wrestler1Deposit + wrestler2Deposit;
    EndOfWrestlingEvent(winner, gains);
}

/**
* The withdraw function, following the withdraw pattern shown and explained here: 
* http://solidity.readthedocs.io/en/develop/common-patterns.html#withdrawal-from-contracts
*/
function withdraw() public {
    require(gameFinished && theWinner == msg.sender);

    uint amount = gains;

    gains = 0;
    msg.sender.transfer(amount);
}

}

@itinance
Copy link
Contributor

Any news on this?

@SumitRajpal
Copy link

I was facing the same issue solved it by adding "0x" to the bytecode

`const HDWalletProvider = require("truffle-hdwallet-provider");
const Web3 =require('web3');
const { interface, bytecode } = require('./compile');
const mnemonic = "jewel renew rate forest fuel boost screen winter throw space can weather";
const provider = new HDWalletProvider(mnemonic,"https://ropsten.infura.io/W727SZ47Z2PgLGnLbriG");
const web3 = new Web3(provider);

deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy',accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface)).deploy({ data:'0x'+bytecode,arguments:['Hi svgjkbnlsdfkjbvg there']}).send({from:accounts[0],gas:'300000'});
console.log('contract deployed',result.options.address);
};
deploy();`

@piggyman007
Copy link

@SumitRajpal

thanks, your working around works

@gnidan
Copy link
Contributor

gnidan commented Jan 9, 2019

Closing this as duplicate of #522.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests