Ropsten

為什麼 view 方法在部署到測試網路時會無緣無故地恢復,但在 localhost 上工作正常?

  • October 26, 2021

我一直在用 Hardhat 開發沒有問題。當我將智能合約部署到測試網路(Ropsten 或 Rinkeby)時,我的view方法都不起作用。例如:

function testView() public virtual view returns(bool) {
   return true;
 }

即使我的交易功能執行良好,此功能也將始終在所有測試網路上恢復。還原異常是:

An unexpected error occurred:

Error: call revert exception (method="testView()", errorArgs=null, errorName=null, errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.4.1)
   at Logger.makeError (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
   at Logger.throwError (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
   at Interface.decodeFunctionResult (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/abi/src.ts/interface.ts:425:23)
   at Contract.<anonymous> (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/src.ts/index.ts:332:44)
   at step (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/lib/index.js:48:23)
   at Object.next (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/lib/index.js:29:53)
   at fulfilled (/Users/zaneclaes/zdrive/zaneclaes/Programming/Furballs/node_modules/@ethersproject/contracts/lib/index.js:20:58)
   at processTicksAndRejections (node:internal/process/task_queues:96:5) {
 reason: null,
 code: 'CALL_EXCEPTION',
 method: 'testView()',
 errorArgs: null,
 errorName: null,
 errorSignature: null,
 address: '0x27AbaB051007f7325ac2246187DD92b513B26d39',
 args: [ ],
 transaction: {
   data: '0x24d7806c000000000000000000000000809e2b319e4d398f9282167271ed2f69d63ef6be',
   to: '0x27AbaB051007f7325ac2246187DD92b513B26d39',
   gasLimit: BigNumber { _hex: '0x05f5e100', _isBigNumber: true },
   from: 'xxxxxx'
 }
}

AFAICT,這可能與類似的錯誤有關,其中交易需要 gasLimit。如果我在部署時嘗試執行某些事務,我第一次(僅)收到:

Error: cannot estimate gas; transaction may fail or may require manual gas limit

添加 a{ gasLimit }確實可以解決該問題。

ethersjs 上的這個GitHub 問題堅持認為我的錯誤是由於使用了“錯誤的網路”造成的,而這確實是問題所在。具體來說,我錯誤地配置了我的部署文件,以至於 Ropsten 和 Rinkeby 被倒置保存,這樣每個人都在使用另一個人的合約地址。

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