【问题标题】:Transaction REVERT error using Web3.py and local Ganache instance使用 Web3.py 和本地 Ganache 实例的事务 REVERT 错误
【发布时间】:2022-08-31 08:16:47
【问题描述】:

尝试使用 web3.py 对本地 Ganache 实例进行部署/交易。我可以从已部署的合同中读取数据。我还可以通过 Truffle 读/写。

起初我认为合同有问题,但使用空合同我仍然遇到同样的错误:

from solcx import compile_source, compile_files

source = \'\'\'
pragma solidity >=0.4.22 <0.9.0;

contract TruffleTutorial {
}
\'\'\'
compiled_sol = compile_source(
    source,
    output_values=[\"abi\", \"bin-runtime\"],
    solc_version=\"0.8.9\")

contract_id, contract_interface = compiled_sol.popitem()
bytecode = contract_interface[\'bin-runtime\']
abi = contract_interface[\'abi\']
dummyContract = w3.eth.contract(abi=abi, bytecode=bytecode)
nonce = w3.eth.getTransactionCount(Web3.toChecksumAddress(address))+1
txn = dummyContract.constructor().buildTransaction({
    \"chainId\": 1337,
    \"gasPrice\": w3.eth.gas_price,
    \"from\": w3.eth.accounts[0],
    \"nonce\": nonce
})

错误是:

PUSH1
PUSH1
MSTORE
PUSH1
DUP1
REVERT
 <   {
 <     \"id\": 43,
 <     \"jsonrpc\": \"2.0\",
 <     \"error\": {
 <       \"message\": \"VM Exception while processing transaction: revert\",
 <       \"code\": -32000,
 <       \"data\": {
 <         \"stack\": \"c: VM Exception while processing transaction: revert\\n    at Function.c.fromResults (/Users/me/some/path/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\\n    at e.exports (/Users/me/some/path/node_modules/ganache-cli/build/ganache-core.node.cli.js:55:2089395)\",
 <         \"name\": \"c\"
 <       }
 <     }
 <   }

    标签: solidity web3py ganache


    【解决方案1】:

    我可以发誓堆栈跟踪中没有错误,但是在发布此问题后,我看到了对“fill_transaction_defaults”的引用,因此我添加了如下所示的气体并且它起作用了!

    txn = dummyContract.constructor().buildTransaction({
      "chainId": 1337,
      "gasPrice": w3.eth.gas_price,
      "gas": 1728712,
      "from": w3.eth.accounts[0],
      "nonce": nonce })
    

    【讨论】:

      猜你喜欢
      • 2020-01-29
      • 2023-03-18
      • 2022-01-01
      • 1970-01-01
      • 2022-01-03
      • 2020-05-18
      • 2019-12-26
      • 2021-11-28
      • 2020-10-04
      相关资源
      最近更新 更多