【发布时间】: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\"
< }
< }
< }