简体   繁体   English

web3 ABI 无法在以太坊主网上获得合约所有权

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

I'm working on python with web3 APIs.我正在使用 web3 API 处理 python。 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.也许 ABI 不适用于此 RPC,或者不知道发生了什么。 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).查询的合约( 源代码)没有owner()函数(也没有会自动生成 getter 函数的公共财产owner )。

When you're trying to call a non-existing function, the EVM then tries to call the fallback() ( docs ).当您尝试调用不存在的函数时,EVM 会尝试调用fallback() ( docs )。 But it's not there either, so the call fails.但它也不存在,所以调用失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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