Go-Ethereum

Gas 估計錯誤並顯示以下消息…錯誤:所需的氣體超出限額或總是失敗的交易

  • May 2, 2018

我做了一個智能合約,但在部署它時出現錯誤,在我指定了 3000000 的 Gas 限制和一個隨機值 (wei) 後,點擊 Create,我收到以下錯誤:

(我正在使用 Remix IDE、Metatmask 擴展和 Ropsten 網路。我的餘額中有 10 個 Eth,我也嘗試使用solidity 編譯器 0.4.9 和 0.4.20,但仍然遇到相同的錯誤)

錯誤 :

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? 
Error: gas required exceeds allowance or always failing transaction at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:1391377 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:927906 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:346093 at o (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:364324) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:348923 at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:346093 at c (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:349199) at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:349237 at Ht (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:358606) at Object.<anonymous> (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:349326) at e.value (chrome-

這是我的程式碼:

pragma solidity ^0.4.21;

contract admined{
   address public admin;

   function admined(){
       admin = msg.sender;
   }

   modifier onlyAdmin(){
       require(msg.sender == admin);
       _;
   }

   function transferAdminRol(address newAdmin)public onlyAdmin {
       admin = newAdmin;
   }

}

contract ERC20{

   mapping(address => uint256) public balanceOf;
   mapping(address => mapping(address => uint256)) public allowance;

   string public standard = "Test Africa v0.1";
   string public name;
   string public symbol;
   uint8 public decimal; 
   uint256 public totalSupply;

   event Transfer(address indexed from, address indexed to, uint256 value);
   event Approval(address indexed owner, address indexed spender, uint256 value);

   function ERC20(uint256 initialSupply, string _name, string _symbol, uint8 _decimal) public{
       balanceOf[msg.sender] = initialSupply;
       name = _name;
       symbol = _symbol;
       decimal = _decimal;
       totalSupply = initialSupply;
   }

   function transfer(address _to, uint256 _value)public returns (bool success){
      require(balanceOf[msg.sender] >= _value);
      require(balanceOf[_to] + _value >= balanceOf[_to]);

       balanceOf[msg.sender] -= _value;
       balanceOf[_to] += _value;
       emit Transfer(msg.sender, _to, _value);
       return true;
   }

   function approve(address _spender, uint256 _value) public returns (bool success){
       allowance[msg.sender][_spender] = _value;
       emit Approval(msg.sender, _spender, _value);
       return true;
   }

   function allowance(address _owner, address _spender) public returns (uint256 remaining) {
     return allowance[_owner][_spender];
   }
   function transferFrom(address _from, address _to, uint256 _value)public returns (bool success){
       require(balanceOf[_from] >= _value);
       require(balanceOf[_to] + _value >= balanceOf[_to]);
       require(_value <= allowance[_from][msg.sender]); 

       balanceOf[_from] -= _value;
       balanceOf[_to] += _value;
       allowance[_from][msg.sender] -= _value;
       emit Transfer(_from, _to, _value);

       return true;
   }

   function balanceOf(address _owner)public constant returns (uint256 balance) {
       return balanceOf[_owner];
   }
}

contract testaAFC is admined, ERC20{

   uint public minBalanceForAccounts = 50000000000000 wei;

   uint256 public sellPrice = 500;
   uint256 public buyPrice = 500;

   bytes32 public currentChallenge;                         
   uint public timeOfLastProof;                             
   uint public difficulty = 10**32;                            

   mapping (address => bool) public frozenAccount;
   event FrozenFunds(address target, bool frozen);

   function testaAFC(uint256 initialSupply, string _name, string _symbol, 
           uint8 _decimal, address _admin)public  ERC20(0, _name, _symbol, _decimal){

       if(_admin != 0)
           admin = _admin;
       else
           admin = msg.sender;

       balanceOf[admin] = initialSupply;
       totalSupply = initialSupply;

   }

   function transfer(address _to, uint256 _value)public returns (bool success){
      //
   }

   function transferFrom(address _from, address _to, uint256 _value)public returns (bool success){
    //
   }

   function setMinBalance(uint minimumBalanceInFinney)public onlyAdmin {
        minBalanceForAccounts = minimumBalanceInFinney * 1 wei;
   }



   function mintToken(address target, uint256 mintedAmount)public onlyAdmin {
       balanceOf[target] += mintedAmount;
       totalSupply += mintedAmount;
       emit Transfer(0, this, mintedAmount);
       emit Transfer(this, target, mintedAmount);
   }

   function setPrices(uint256 newSellPrice, uint256 newBuyPrice)public onlyAdmin {
       sellPrice = newSellPrice;
       buyPrice = newBuyPrice;
   }

   function buy()public payable returns (uint amount){
       amount = msg.value * buyPrice;                   
       require(balanceOf[this] >= amount);               
       balanceOf[msg.sender] += amount;                  
       balanceOf[this] -= amount;                        
       emit Transfer(this, msg.sender, amount);               
       return amount;                                  
   }

   function sell(uint amount)public returns (uint revenue){
       require(balanceOf[msg.sender] >= amount);         
       balanceOf[this] += amount;                        
       balanceOf[msg.sender] -= amount;                  
       revenue = amount / sellPrice;                     
       msg.sender.transfer(revenue);                     
       emit Transfer(msg.sender, this, amount);             
       return revenue;                                 
   }

}

請幫助我很著急謝謝!

value除非您希望將一些 ETH 與您的交易一起轉移,否則無需在欄位中輸入任何值。還要記住payable在任何這種情況下使用關鍵字。

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