我们可以通过提供合同地址从web3.py获得令牌名称吗



例如,我们可以通过提供其合同地址0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48来返回"USDC"吗?

您可以使用Web3.py模块:

from web3 import Web3
import json
web3 = Web3(Web3.HTTPProvider('https://rpc.ankr.com/eth'))
abi = [{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]
address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'

contract = web3.eth.contract(address , abi = abi)
token_name = contract.functions.name().call() 
token_symbol = contract.functions.symbol().call() 
print('Name:', token_name)
print('Symbol:', token_symbol)

有关更多示例,您可以参考本文档。

相关内容

  • 没有找到相关文章