【发布时间】:2021-07-01 11:03:17
【问题描述】:
我正在尝试通过使用 Python 的 web3 模块来了解更多关于 dapp 的信息。 Web3 可以很好地连接到 Ganache,我可以使用 web3.eth.accounts[0] 查看我的帐户,并且可以检索我的合同。但是,当我尝试从我的合同中调用一个函数时,我得到以下信息:
web3.exceptions.ContractLogicError: execution reverted: VM Exception while processing transaction: revert
这是我的python代码:
from web3 import Web3
import json
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:7545'))
w3.eth.defaultAccount = w3.eth.accounts[0]
print(w3.eth.defaultAccount)
compiled_contract_path = './build/contracts/Greeter.json'
deployed_contract_address = '0x54BB58167CDB31A98F56E8Fc3CfbAC43bf867000'
with open(compiled_contract_path) as file:
contract_json = json.load(file) # load contract info as JSON
contract_abi = contract_json['abi']
contract = w3.eth.contract(address=deployed_contract_address, abi=contract_abi)
print(contract.functions.greet().call())
这是我的合同:
pragma solidity ^0.5.0;
contract Greeter {
uint public taskCount = 0;
string public greeting;
constructor() public {
greeting = 'Hello';
}
function greet() public returns (string memory) {
return greeting;
}
}
对于理解错误的任何帮助将不胜感激。
【问题讨论】:
标签: python blockchain web3 web3py