1

I have a simple token derived from openzeppelin's MintableToken.

However, when I either add a Constructor OR another function, I am constantly running out of gas. But when I add ONLY one of both, either the Constructor OR the function, everything works fine.

My question is: how can I add several functions together with a constructor into my SmartContract?

The Token-Code:

pragma solidity ^0.4.22;

import "openzeppelin-solidity/contracts/token/ERC20/MintableToken.sol";

contract HaioToken is MintableToken {
    string public name = "Haio Token";
    string public symbol = "HAI";
    uint8 public decimals = 18;

    uint256 public cap;

    constructor(uint256 _cap) public {
        cap = _cap;
    }

    function test(address _to) public returns (bool) {
        return true;    
    }

}

Migrations:

2_deploy_contracts.js:

var HaioToken = artifacts.require("HaioToken");

module.exports = function(deployer, network, accounts) {
  const hardCap = 25000000;

  return deployer
      .then(() => {
          return deployer.deploy(HaioToken, hardCap);
      })
};

When I want to deploy the code, I get the following error message:

Error: VM Exception while processing transaction: out of gas

If I remove either the constructor or the test-function, everything works fine.

delete
  • 18,144
  • 15
  • 48
  • 79

1 Answers1

1

I guess you are running the migration with truffles default settings that came out of the box after running "truffle init" isn't it?

You should raise the gas you want to send on contract deployment this way in truffle.js (or truffle-config.js on Windows):

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 7545,
      network_id: "*",
      gas: 5000000
    }
  }
};

(The value of 5000000 is an example that mostly works out of the box and if you don't have to care because developing on a local testnet :) )

itinance
  • 11,711
  • 7
  • 58
  • 98