例如,我们可以通过提供合约地址 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)
更多示例可以引用this文档。
关于web3py - 我们可以通过提供合约地址从 web3.py 获取代币名称吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74132965/