Ethers.js
部署到 Goerli 測試網後的錯誤
我在fleek.co 上託管了我的彩票網站,並且在安全帽本地網路上一切正常。所以我決定在 Goerli 上對其進行測試,但我面臨一個又一個錯誤。
起初我得到下面的錯誤 1 並在安全帽配置文件中手動添加了氣體限制。在重新部署合約並在 Flek 上發布後,首先 enterRaffle 工作正常。
當我第二次嘗試進入Raffle 時,它失敗了。其他時候是成功的。但即便如此,它也不會像預期的那樣更新玩家的數量。
我錯過了什麼?
錯誤 1
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"code":-32603,"message":"execution reverted","data":{"originalError":{"code":3,"data":"0x1425571c","message":"execution reverted"}}}, method="estimateGas", transaction={"from":"0x13A19933267ec307c96f3dE8Ff8A2392C39263EB","to":"0x5507C7e274B5201a98141cCd0507cF6e4416Be30","value":{"type":"BigNumber","hex":"0x2386f26fc10000"},"data":"0x2cfcc539","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.6.0) at su.makeError (_app-3ca186e4a2557e86.js:1:1975135) at su.throwError (_app-3ca186e4a2557e86.js:1:1975255) at yh (_app-3ca186e4a2557e86.js:1:2115696) at Ad.<anonymous> (_app-3ca186e4a2557e86.js:1:2123240) at Generator.throw (<anonymous>) at s (_app-3ca186e4a2557e86.js:1:2114235)
然後像這樣手動添加氣體後,出現錯誤2。
goerli: { url: GOERLI_RPC_URL, accounts: PRIVATE_KEY !== undefined ? [PRIVATE_KEY] : [], // accounts: { // mnemonic: MNEMONIC, // }, saveDeployments: true, chainId: 5, gas: 6000000, },
錯誤 2
_app-3ca186e4a2557e86.js:1 Uncaught (in promise) Error: transaction failed [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (transactionHash="0x1c28a6b2bfb02f23f443a854c998bec3d965a6beff525f0431480d063e5214c2", transaction={"hash":"0x1c28a6b2bfb02f23f443a854c998bec3d965a6beff525f0431480d063e5214c2","type":2,"accessList":null,"blockHash":null,"blockNumber":null,"transactionIndex":null,"confirmations":0,"from":"0x13A19933267ec307c96f3dE8Ff8A2392C39263EB","gasPrice":{"type":"BigNumber","hex":"0x6bc0e597"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"maxFeePerGas":{"type":"BigNumber","hex":"0x6bc0e597"},"gasLimit":{"type":"BigNumber","hex":"0x4c9e58"},"to":"0x5507C7e274B5201a98141cCd0507cF6e4416Be30","value":{"type":"BigNumber","hex":"0x2386f26fc10000"},"nonce":49,"data":"0x2cfcc539","r":"0x3869c8f2e2ecaa492c528f2065d156cdb855a6f2af9669a5472c97473f6f5d74","s":"0x1ae3086d065b24e61c4a01ea1a25a4e1109a809e8a5e8c40fba7a58d8c8e05b2","v":0,"creates":null,"chainId":0}, receipt={"to":"0x5507C7e274B5201a98141cCd0507cF6e4416Be30","from":"0x13A19933267ec307c96f3dE8Ff8A2392C39263EB","contractAddress":null,"transactionIndex":18,"gasUsed":{"type":"BigNumber","hex":"0x6448"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x4cc5aa906cc1a68ef49ade23bec8f679abeb0c2439cc2798d9f5244550bcb8a4","transactionHash":"0x1c28a6b2bfb02f23f443a854c998bec3d965a6beff525f0431480d063e5214c2","logs":[],"blockNumber":7723284,"confirmations":2,"cumulativeGasUsed":{"type":"BigNumber","hex":"0x28a252"},"effectiveGasPrice":{"type":"BigNumber","hex":"0x67d1c29b"},"status":0,"type":2,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.6.0) at su.makeError (_app-3ca186e4a2557e86.js:1:1975135) at su.throwError (_app-3ca186e4a2557e86.js:1:1975255) at Ad.<anonymous> (_app-3ca186e4a2557e86.js:1:2091815) at Generator.next (<anonymous>) at a (_app-3ca186e4a2557e86.js:1:2072233)
在我看來,它與列舉有關 - 它不會將其狀態重置回 OPEN (我看到它發生在 fullyrandomwords() 函式中。
我的 2 條建議:
- 確保合約連結到一個訂閱,其中包含足夠的測試連結
- 這也可能是由於用模數四捨五入 randomWords 數。在
fullfillRandomWords()
函式中,在第 154 行,您可以嘗試將其更改為:uint256 indexOfWinner = (randomWords[0] % s_players.length)*1 ;
我希望這會有所幫助。
氣體估算是通過虛擬執行程式碼來完成的。如果程式碼出錯,應用程序將無法估計氣體。即使您手動設置了 gas 並仍然呼叫該函式,這一次它會在 evm 上執行並且仍然是一個失敗的交易。
在您的情況下,如果應用程序在您呼叫 enterRaffle 時給出“錯誤:無法估計氣體”,或者 RaffleState 在呼叫時未打開或金額小於 i_enteranceFee。