Testrpc

使用提款模式時出現“錯誤:基礎費用超過 gas 限制”

  • July 24, 2017

當我使用 Remix 和 testrpc 測試withdraw()來自http://solidity.readthedocs.io/en/develop/common-patterns.html的“WithdrawalContract”方法時,它報告了以下錯誤。Testrpc 氣體限制設置為 0xffffff。關於為什麼會出現這個問題的任何提示?

callback contain no result Error: Error: base fee exceeds gas limit
at runCall (/home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:88096:17)
at /home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:11855:24
at replenish (/home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8948:17)
at iterateeCallback (/home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8933:17)
at /home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8908:16
at /home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:11860:13
at /home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:74400:16
at replenish (/home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:74347:25)
at /home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:74356:9
at eachLimit (/home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:74280:36)
at /home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:75460:16
at VM.AsyncEventEmitter.emit (/home/chankh/anaconda3/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:74051:3)

僅供參考,合約程式碼是

pragma solidity ^0.4.11;

contract WithdrawalContract {
   address public richest;
   uint public mostSent;

   mapping (address => uint) pendingWithdrawals;

   function WithdrawalContract() payable {
       richest = msg.sender;
       mostSent = msg.value;
   }

   function becomeRichest() payable returns (bool) {
       if (msg.value > mostSent) {
           pendingWithdrawals[richest] += msg.value;
           richest = msg.sender;
           mostSent = msg.value;
           return true;
       } else {
           return false;
       }
   }

   function withdraw() {
       uint amount = pendingWithdrawals[msg.sender];
       // Remember to zero the pending refund before
       // sending to prevent re-entrancy attacks
       pendingWithdrawals[msg.sender] = 0;
       msg.sender.transfer(amount);
   }
}

呼叫 selfdestruct 函式(使用 Remix IDE)時,您是否閱讀過此“回調不包含結果錯誤:錯誤:基本費用超過 gas 限制” ?

我建議使用 MyEtherWallet 測試您的合約。設置非常簡單:

  1. 訪問https://www.myetherwallet.com/
  2. 在右上角,選擇下拉菜單並選擇“添加自定義節點”
  3. 添加執行 testrpc 的 IP 地址和埠號(通常是http://127.0.0.1:8545
  4. 轉到合約選項卡並插入合約地址(使用 Remix 部署)及其 ABI 介面

現在您可以與您的合約進行互動。

在您的範例中,我witdraw()使用氣體限制 30000 呼叫了該函式,並且它可以工作。

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