I'm trying to deploy a contract using Truffle v4.0.1, within Truffle's own console but I keep getting out of gas errors.

The constructor looks like:

function MyAwesomeCrowdsale(
    uint64 _startTime,
    uint64 _endTime,
    uint256 _rate,
    uint256 _presaleRate,
    address _wallet,
    address _foundationPool,
    address _foundersPool,
    address _legalExpensesWallet,
    uint256 _goal
) public
    require(_endTime > _startTime);
    require(_rate > 0);
    require(_wallet != 0x0);

    token = new MyAwesomeToken(TOTAL_SUPPLY_CAP);
    // mints all tokens and gives them to the crowdsale
    token.mint(address(this), TOTAL_SUPPLY_CAP);

    startTime = _startTime;
    endTime = _endTime;
    rate = _rate;
    presaleRate = _presaleRate;
    wallet = _wallet;
    goal = _goal;

    vault = new MyAwesomeRefundVault(wallet);

    foundationPool = _foundationPool;
    foundersPool = _foundersPool;
    legalExpensesWallet = _legalExpensesWallet;

    // Set timelocks to 1 year after startTime
    uint64 unlockAt = uint64(startTime + 31622400);
    timelockFounders = new TokenTimelock(token, foundersPool, unlockAt);


I hit out of gas error at the line:

timelockFounders = new TokenTimelock(token, foundersPool, unlockAt);

TokenTimelock is imported from zeppelin-solidity/contracts/token/TokenTimelock.sol

If I comment that out then everything deploys just fine, but with that line in there, no amount of messing about with default gas and gasPrice values helps at all.

How can I reliably estimate the gas needed to deploy this contract?


Truffle 4.0 has optimization turned off by default, so you'll probably want to both increase supplied gas and turn optimization on so the gas used on creation is considerably reduced:

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*", // Match any network id
      gas: 4500000
  solc: {
    optimizer: {
      enabled: true,
      runs: 200
| improve this answer | |

Inside truffle.js, add more gas:

module.exports = {
  migrations_directory: "./migrations",
  networks: {
        rinkeby: {
          provider: new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/"),
          gas: 4500000,
          network_id: 4
| improve this answer | |
  • I'm specifically trying to do this within the truffle console not an external blockchain. – Dave Sag Nov 21 '17 at 13:00

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.