简体   繁体   中英

web3 ABI doesn't work to get contract ownership on Ethereum mainnet

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. Does somebody can help me? Thanks.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM