File size: 1,107 Bytes
d1e2e7a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import requests
from web3 import Web3
class find:
INFURA_URL = "https://polygon-mainnet.infura.io/v3/16185d569adf4d00a04f2d2a200cf231"
web3 = Web3(Web3.HTTPProvider(INFURA_URL))
token_contract_address = "0xYourTokenContractAddress"
contract_abi = [
{
"constant": True,
"inputs": [{"name": "_tokenId", "type": "uint256"}],
"name": "tokenURI",
"outputs": [{"name": "", "type": "string"}],
"payable": False,
"stateMutability": "view",
"type": "function"
},
]
@classmethod
def name(cls, token_id):
contract = cls.web3.eth.contract(address=cls.token_contract_address, abi=cls.contract_abi)
token_uri = contract.functions.tokenURI(token_id).call()
metadata_response = requests.get(token_uri)
metadata = metadata_response.json()
return metadata.get("name", "Name not found")
# μ¬μ©μκ° μ΄ λͺ¨λμ import νμ¬ λ€μκ³Ό κ°μ΄ μ¬μ©ν μ μμ΅λλ€.
# import nameft as nft
# name = nft.NFTNameFetcher.name(token_id)
# print(name)
|