Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用web3.py获取给定ETH地址上的特定令牌余额_Python_Python 3.x_Web3_Web3js - Fatal编程技术网

Python 如何使用web3.py获取给定ETH地址上的特定令牌余额

Python 如何使用web3.py获取给定ETH地址上的特定令牌余额,python,python-3.x,web3,web3js,Python,Python 3.x,Web3,Web3js,我正在开始使用web.py。我有一个要求,即我需要在给定的ETH地址(该地址不是合同所有人)获得可用的代币余额,通过这些文件,我偶然发现了以下功能: 在上面的几行中,我写了这样一句话: from web3 import HTTPProvider, Web3 import requests w3 = Web3(HTTPProvider('https://ropsten.infura.io/RPw9nHRS7Ue47RaKVvHM')) url_eth = "https://api.ether

我正在开始使用web.py。我有一个要求,即我需要在给定的ETH地址(该地址不是合同所有人)获得可用的代币余额,通过这些文件,我偶然发现了以下功能:

在上面的几行中,我写了这样一句话:

from web3 import HTTPProvider, Web3
import requests

w3 = Web3(HTTPProvider('https://ropsten.infura.io/RPw9nHRS7Ue47RaKVvHM'))

url_eth = "https://api.etherscan.io/api"
contract_address = '0x0CdCdA4E7FCDD461Ba82B61cBc4163E1022f22e4'
API_ENDPOINT = url_eth+"?module=contract&action=getabi&address="+str(contract_address)

r = requests.get(url = API_ENDPOINT)
response = r.json()

instance = w3.eth.contract(
    address=Web3.toChecksumAddress(contract_address),
    abi = response["result"]
)
send_address = "0xF35A192475527f80EfcfeE5040C8B5BBB596F69A"
balance = instance.functions.balance_of.call({'from':send_address}) 
#balnce = instance.functions.myBalance.call({'from':send_address})
print("----------------------",balance)
我得到以下错误:

"Are you sure you provided the correct contract abi?"
web3.exceptions.MismatchedABI: ("The function 'balance_of' was not foundin this contract's abi. ", 'Are you sure you provided the correct contract abi?')
**更新**我消除了上述异常,现在我得到以下异常:

send_address = "0xF35A192475527f80EfcfeE5040C8B5BBB596F69A"
balance = instance.functions.balanceOf.call(send_address)
#Error :
call_transaction = dict(**transaction)
TypeError: type object argument after ** must be a mapping, not str
如果我尝试这样做:

send_address = "0xF35A192475527f80EfcfeE5040C8B5BBB596F69A"
balance = instance.functions.balanceOf.call({'from':send_address})
#Error:
AttributeError: 'balanceOf' object has no attribute 'args'

在上一个代码示例中,尝试修改第二行,使其如下所示:
balance=instance.functions.balanceOf().call({'from':send_address})
。balance of后的括号是传递给solidity函数的参数。

您必须查看合同是否具有“balance of”函数。执行时

balance = instance.functions.balanceOf.call(send_address)
您正在执行合同功能的平衡,如果合同没有该功能,它将给出错误

balance = instance.functions.balanceOf.call(send_address)