简体   繁体   English

如何使用 web3 Api Python 获得智能合约的所有权?

[英]How to get ownership of smart contract using web3 Api Python?

I am practicing with web3 APIs and Python.我正在练习 web3 API 和 Python。 I would like to extract the ownership of a specific smart contract giving the contract address (or smart contract) as input and getting as output the ownership of the contract.我想提取特定智能合约的所有权,将合约地址(或智能合约)作为输入,并获取合约的所有权作为输出。

For example if I check this contract 0x2A9718defF471f3Bb91FA0ECEAB14154F150a385 on BscScan reading the contract on point n.11 I can see the ownership is owned by this address 0x42997cf4fc165ebb8269cffc54a3198984367f02 .例如,如果我0x2A9718defF471f3Bb91FA0ECEAB14154F150a385 查看此合同0x2A9718defF471f3Bb91FA0ECEAB14154F150a385读取n.11点的合同,我可以看到所有权归该地址0x42997cf4fc165ebb8269cffc54a3198984367f02 How to automatize this process with web3 APIs on python?如何使用 python 上的 web3 API 自动化这个过程? Or do you know any other method to get it except of selenium webdriver?或者你知道除了 selenium webdriver 之外的任何其他方法吗?

I'm not using web3 and bitcoins but digging in internet (using Google ) I found similar portal with questions about Ethereum and question web3js - How to get value of a contract public property using web3.eth with code in JavaScript我没有使用web3bitcoins而是在互联网上挖掘(使用Google )我发现了类似的门户网站,其中包含有关以太坊的问题和问题web3js - 如何使用 web3.ethJavaScript代码获取合同公共财产的价值

Digging in Python examples on internet I created version in Python在互联网上挖掘 Python 示例我在 Python 中创建了版本

from web3 import Web3

bsc = "https://bsc-dataseed.binance.org/"
web3 = Web3(Web3.HTTPProvider(bsc))

print("connected:", web3.isConnected())

abi = '''[
    {
      "constant": true,
      "inputs": [],
      "name": "owner",
      "outputs": [
        {
          "name": "",
          "type": "address"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "inputs": [],
      "payable": false,
      "type": "constructor"
    }
]'''

contract = web3.eth.contract(address="0x2A9718defF471f3Bb91FA0ECEAB14154F150a385", abi=abi)
owner = contract.functions.owner().call()

print("owner:", owner)

And this gives me 0x42997cf4fc165ebb8269cffc54a3198984367f02这给了我0x42997cf4fc165ebb8269cffc54a3198984367f02

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

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