Truffle

合約程式碼無法儲存,請檢查您的gas量。從epelin,T_rufF樂。_js,羅普斯滕______從和pp和l一世n,噸r在FFl和.js,R這ps噸和nZeppelin, Truffle.js, Ropsten

  • August 2, 2018

我在將簡單的令牌合約部署到 Ropsten 網路時遇到了一些問題。

錯誤是“無法儲存合約程式碼,請檢查您的gas量”。

我試圖在“Truffle.js”文件中多次更改 Gas 值,似乎我在“TestToken.sol”文件中沒有任何抽象函式。

軟體是最新的。但是我仍然無法弄清楚問題是什麼,我只是一個初學者,所以請幫助我,不勝感激!

// truffle.js
require('dotenv').config();
const HDWalletProvider = require("truffle-hdwallet-provider");
module.exports = {
 networks: {
development: {
 host: "localhost",
 port: 9545,
 gas: 6712390,
 network_id: "*"
},
ropsten: {
   provider: function() { 
     return new HDWalletProvider(process.env.MNENOMIC, "https://ropsten.infura.io/" + process.env.INFURA_API_KEY) },
   network_id: 3,
   gas: 4700000,
   },
 }
};

//TestToken.sol

pragma solidity ^0.4.24;


import "zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol";
import "zeppelin-solidity/contracts/math/SafeMath.sol";


contract TestToken is ERC20Basic {
   using SafeMath for uint;
   string public name;
   string public symbol;
   uint8 public decimals;
   uint public _totalSupply;


   mapping(address => uint) balances;
   mapping(address => mapping(address => uint)) allowed;


   function TestToken() public {
       name = "TestToken";
       symbol = "tttest";
       decimals = 18;

       _totalSupply = 4000000000000000000000000000;
       balances[0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328] = _totalSupply;
       Transfer (address(0), 0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328, _totalSupply); 
    }
}

TestToken直接繼承自ERC20Basic. ERC20Basic是一個interface。這意味著在部署之前TestToken必須實現聲明的抽象方法。ERC20Basic

你得到的錯誤並不指向這個問題,我認為這是一個缺陷,但是當你嘗試部署一個沒有實現所有抽象方法的合約時就會拋出它。

提示:不要從 OpenZeppelin 繼承,而是ERC20Basic使用StandardToken. 它實現了創建 ERC-20 代幣所需的所有功能

文件:

試試這個合約:

pragma solidity 0.4.24;

import "http://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
import "http://github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";

contract TestToken is StandardToken {
   using SafeMath for uint;
   string public name;
   string public symbol;
   uint8 public decimals;
   uint public _totalSupply;


   mapping(address => uint) balances;
   mapping(address => mapping(address => uint)) allowed;


   constructor() public {

       name = "TestToken";
       symbol = "tttest";
       decimals = 18;
       _totalSupply = 4000000000000000000000000000;
       balances[0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328] = _totalSupply;
       emit Transfer (address(0), 0xE3FdfaAF08F4778c7E88Ed1E31696745ed610328, _totalSupply); 
   }
}

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