[英]ContractLogicError while using web3.py
我正在嘗試通過使用 Python 的 web3 模塊來了解更多關於 dapp 的信息。 Web3 可以很好地連接到 Ganache,我可以使用web3.eth.accounts[0]
查看我的帳戶,並且可以檢索我的合同。 但是,當我嘗試從我的合同中調用 function 時,我得到以下信息: 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;
}
}
任何幫助理解錯誤將不勝感激。
從已編譯的合約文件中讀取 abi 和字節碼是有效的。
代替:
print(contract.functions.greet().call())
嘗試:
callGreeting = contract.functions.greet().call()
print(callGreeting)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.