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

Deploy on Ropsten fails with Message "The contract code couldn't be stored, please check your gas amount" #1003

Closed
tomerweisman opened this issue Jun 12, 2018 · 7 comments

Comments

@tomerweisman
Copy link

tomerweisman commented Jun 12, 2018

Issue

Deploying to Ropsten using truffle and Infura works in a dry run. this is the output:

Using network 'ropsten' (dry run).

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0x5eef3c9ad54451a14e091661b4deb7ff9be1455236f5217d47e970c923532416
  Migrations: 0x89b80afa55d76d0c0f1844ad246752f54bec2462
Saving successful migration to network...
  ... 0x57e9906d8f626c67d94a6ef172daf5326fb5d65ac6b97db3af076f41f101e1e5
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Running step...
  Deploying CoolToken...
  ... 0x03ad2f94e22b3014d6828c68b3f925a17984a9031d0108267164e0aa9642baf8
  OlamToken: 0xbd28ea4350e166e55745c3e3196ae3a9182a189b
deployed token address: 0xbd28ea4350e166e55745c3e3196ae3a9182a189b
  Deploying CoolCrowdsale...
  ... 0xcbd85f521709cafd7d3cae43faf74f55a77b5a605625f84d7875ca9b464f5ec3
  CoolCrowdsale: 0xd87712d295c58dad2984b8860536b7fc9014c682
deployed crowdsale address:  0xd87712d295c58dad2984b8860536b7fc9014c682

BUT, when trying to deploy to the network itself I get the following error:

Using network 'ropsten'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0x265089d4f93b7b5314083d5f378b8794c177d458051a9c5e491a756419081c23
  Migrations: 0xff5f2f6f54f1abfde8ba32b9fd622f01d2d90427
Saving successful migration to network...
  ... 0x96e1bcb981227c2932d7e12d2c9b7ce6019d7721155b34018e2769fba981afa3
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Running step...
  Deploying CoolToken...
  ... 0xe08910347b327fbf7596128fbb41b352bcf3cc215ed4c45bb63c78964529da91
  OlamToken: 0x4086586e97ad802ec252c6383e555e6c7d96f72b
deployed token address: 0x4086586e97ad802ec252c6383e555e6c7d96f72b
  Deploying CoolCrowdsale...
  ... 0x392d9adf3402e48556e3096659d809e143a440c2b22e1e85912cd58e197f70a9
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.

The contracts I try to deploy:

pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/crowdsale/validation/WhitelistedCrowdsale.sol";
import "./PausableCrowdsale.sol";

contract CoolCrowdsale is WhitelistedCrowdsale, PausableCrowdsale {

    event RateChanged(uint indexed oldRate, uint indexed newRate);

    constructor (uint256 _rate, address _wallet, ERC20 _token)
    Crowdsale(_rate, _wallet, _token) public {   }


    function setRate(uint256 _rate) onlyOwner() public {
        require(_rate > 0);
        uint oldRate = rate;
        rate = _rate;
        emit RateChanged(oldRate, rate);
    }
}
pragma solidity 0.4.24;

import "openzeppelin-solidity/contracts/token/ERC20/PausableToken.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

contract CoolToken is PausableToken {

    string public constant name = "Cool Token";
    string public constant symbol = "COOL";
    uint8 public constant decimals = 18;

    constructor (uint256 _initialSupply) public {
        totalSupply_ = _initialSupply;
        balances[msg.sender] = totalSupply_;
   }
}

2_deploy_contracts.js

const CoolToken = artifacts.require("./CoolToken.sol");
const CoolCrowdsale = artifacts.require("./CoolCrowdsale.sol");

module.exports = function (deployer, network, accounts) {
    deployer.then(async function () {

        const wallet = accounts[1];
        const rate = new web3.BigNumber(760 * 10);
        const totalSupply = web3.toWei(1625000000, 'ether');

        await deployer.deploy(CoolToken, totalSupply);
        const deployedToken = await CoolToken.deployed();
        console.log("deployed token address: " + deployedToken.address);

        await deployer.deploy(CoolCrowdsale, rate, wallet, deployedToken.address);
        const deployedCrowdsale = await CoolCrowdsale.deployed();
        console.log('deployed crowdsale address: ', deployedCrowdsale.address);

    })
};

I think I gave a sufficient gas limit and price for the transaction to push through...

truffle-config.js

require('babel-register');
require('babel-polyfill');
require('dotenv').config()
const Web3 = require("web3");
const web3 = new Web3();
const HDWalletProvider = require("truffle-hdwallet-provider");

module.exports = {
    networks: {
        development: {
            host: "127.0.0.1",
            port: 7545,
            network_id: "*",
        },
        ropsten: {
            provider: new HDWalletProvider(process.env.HD_WALLET_MNEMONIC,
            "https://ropsten.infura.io/infura_api_key"),
            gas: 4712388,
            gasPrice: web3.toWei("40", "gwei"),
            network_id: 3,
        },
    },
    solc: {
        optimizer: {
            enabled: true,
            runs: 2000
        }
    }
};

I read almost every issue about this subject and tried so many things (among other #974)
If I needed to add anything here please let me know
I've been working on it for some time...
ANY IDEA ANYONE?

Environment

  • Operating System: Ubuntu 16.04
  • Ethereum client: Infura
  • Truffle version: v4.1.11
  • node version: v9.11.1
  • npm version: v6.1.0
@kyriediculous
Copy link

Possibly related to contract code size limit since homestead - ethereum/EIPs#170

Check out trufflesuite/ganache#674

Reply by @cgewecke :

@XertroV This could be because ganache-cli implements EIP-170 which was included in the Byzantium fork and limits contract sizes. @seesemichaelj (one of the ganache engineers) has been working to make that optional although AFAIK those vm changes haven't made it into a build here yet.

If you need a short term workaround - ethereumjs-testrpc-sc is a coverage enabled ganache fork used by solidity-coverage which has EIP-170 turned off. (It's basically ganache-cli 6.1.0.)


$ npm install --save ethereumjs-testrpc-sc
$ ./node_modules/.bin/testrpc-sc --port 8545 --gasLimit 0xfffffffff # Example launch

@tomerweisman
Copy link
Author

@kyriediculous
thank you for your fast reply.
I don't think it is about the code size limit. I'm trying to deploy crowdsale and token contracts from openzeppelin, which have been deployed many times before. I have added my contracts above for reference.
thank you again

@kyriediculous
Copy link

kyriediculous commented Jun 12, 2018

Right. Shouldn't be an issue then indeed.

Have you tried removing the amount of gas that's being sent in the config file?

PS: Afaik Rinkeby is POA and should be used over Ropsten which often gets rearranged.

@cgewecke
Copy link
Contributor

@tomerweisman Etherscan is suggesting that it's hitting a revert somewhere after consuming about 200k gas. It's kind of frustrating that it passes the dry run ok. . .

If you have a chance could you put a log line in your deploy script and verify that the wallet param has a non-zero address when you use the Ropsten network config?

const wallet = accounts[1]; 

@tomerweisman
Copy link
Author

@cgewecke
you were right! the wallet was undefined.
I entered an address and the crowdsale contract was deployed easily...

**When does the accounts array get defined? only when using ganache? **

thank you so much

@cgewecke
Copy link
Contributor

Oh good. Yes ganache defines 10, and the Wallet only defines one by default.

It would be nice to fix this though because dry-run shouldn't have this kind of variance, otherwise its meaningless.

@tomerweisman
Copy link
Author

agreed. thanks for the help
im closing this issue

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

No branches or pull requests

4 participants
@cgewecke @tomerweisman @kyriediculous and others