首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Web3.py和本地Ganache实例进行事务恢复错误

使用Web3.py和本地Ganache实例进行事务恢复错误
EN

Stack Overflow用户
提问于 2022-08-31 00:12:21
回答 1查看 17关注 0票数 1

尝试使用web3.py部署/处理本地Ganache实例。我能读到一份已部署的合同。我还能读/写松露。

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

代码语言:javascript
运行
复制
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
})

错误是:

代码语言:javascript
运行
复制
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"
 <       }
 <     }
 <   }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-31 00:16:47

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

代码语言:javascript
运行
复制
txn = dummyContract.constructor().buildTransaction({
  "chainId": 1337,
  "gasPrice": w3.eth.gas_price,
  "gas": 1728712,
  "from": w3.eth.accounts[0],
  "nonce": nonce })
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73549643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档