gpt4 book ai didi

web3py - 我们可以通过提供合约地址从 web3.py 获取代币名称吗?

转载 作者:行者123 更新时间:2023-12-03 08:01:13 41 4
gpt4 key购买 nike

例如,我们可以通过提供合约地址 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/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com