Remix

Remix -> 函式呼叫:所需氣體超過限制

  • January 9, 2018

我一直在嘗試將 ERC20 代幣從一個錢包轉移到另一個錢包的簡單功能上出現“氣體超過限制”。我的第一個問題是調試此類錯誤的最有效方法是什麼?其次是有人認為我的功能有什麼問題嗎?

這是錯誤:

Transact to browser/SmartLoan.sol:Loan.sendFunds errored: Gas required exceeds limit: 3000000.  An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation). 

這是呼叫時出錯的函式:

   function sendFunds(address dest, uint amount) public {
       if(totalPayments < loanStatics.totalAmount){

           address addressToken = 0xfef45491b96af14c98b81325cbb7a3fbb83bb7a0;
           abstractToken Token = abstractToken(addressToken);
           Token.transferFrom(msg.sender, dest, amount);

           totalPayments = totalPayments.add(amount);
           payments[msg.sender] = payments[msg.sender].add(amount);
           company = dest;
       }

       if(totalPayments == loanStatics.totalAmount){
           status = Status.funded;
       } else {
           status = Status.partially_funded;
       }
       LoanFunded(status, amount);
   }

以下是我創建契約摘要的方式:

contract abstractToken {
  function transferFrom(address _from, address _to, uint256 _value) public returns (bool);
}

更新

這是控制台的列印螢幕,似乎我的事務甚至沒有創建,或者至少我不知道如何獲取它的雜湊,因此我不確定如何調試它……

在此處輸入圖像描述

您必鬚髮布更多程式碼(目前的內容無法編譯),或者我通常的策略只是註釋掉各個行,然後您可以縮小範圍。但我的猜測是,當你呼叫 abstractToken 合約時。試試這個:

abstractToken Token;

function sendFunds(address dest, uint amount) public {
   if(totalPayments < loanStatics.totalAmount){

       address addressToken = 0xfef45491b96af14c98b81325cbb7a3fbb83bb7a0;
       Token = abstractToken(addressToken);
       Token.transferFrom(msg.sender, dest, amount);

       totalPayments = totalPayments.add(amount);
       payments[msg.sender] = payments[msg.sender].add(amount);
       company = dest;
   }

   if(totalPayments == loanStatics.totalAmount){
       status = Status.funded;
   } else {
       status = Status.partially_funded;
   }
   LoanFunded(status, amount);
}

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