Truffle

TokenTimelock 在 Truffle 4.0.1 中部署時會出現氣體不足錯誤

  • November 21, 2017

我正在嘗試在 Truffle 自己的控制台中使用Truffle v4.0.1部署契約,但我不斷收到out of gas錯誤。

建構子如下所示:

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);
   token.finishMinting();

   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);

   distributeInitialFunds();
}

我在該行遇到out of gas錯誤:

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

TokenTimelock進口自zeppelin-solidity/contracts/token/TokenTimelock.sol

如果我將其註釋掉,那麼一切都部署得很好,但是有了那條線,再多弄亂預設值gasgasPrice值都沒有幫助。

我怎樣才能可靠地估計gas部署此契約所需的時間?

Truffle 4.0 預設關閉優化,因此您可能希望同時增加供應的氣體並打開優化,這樣創建時使用的氣體會大大減少:

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

在 truffle.js 中,添加更多氣體:

module.exports = {
 migrations_directory: "./migrations",
 networks: {
       rinkeby: {
         provider: new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/"),
         gas: 4500000,
         network_id: 4
       }
 }
}

引用自:https://ethereum.stackexchange.com/questions/31247