Reputation: 345
I'm working on python with web3 APIs. I'm trying to get the ownership of contract deployed on ethereum mainnet. The best code I could text was the following:
from web3 import Web3
eth = "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"
web3 = Web3(Web3.HTTPProvider(eth))
abi = '''[
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"type": "function"
},
{
"inputs": [],
"payable": false,
"type": "constructor"
}
]'''
contract = web3.eth.contract(address=Web3.toChecksumAddress("0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"), abi=abi)
owner = contract.functions.owner().call()
print(owner)
But if I try to execute the code I get the following error:
web3.exceptions.ContractLogicError: execution reverted
Maybe ABI doesn't work for this RPC, or idk what occurs.
Upvotes: 0
Views: 1013
Reputation: 43491
The queried contract (source code) doesn't have the owner()
function (nor public property owner
that would autogenerate the getter function).
When you're trying to call a non-existing function, the EVM then tries to call the fallback()
(docs). But it's not there either, so the call fails.
A contract doesn't have to have an owner. It's "just" a widely used pattern, described and implemented by OpenZeppelin and other open-source library authors.
Upvotes: 1