|
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") |
|
|
|
|
|
|
|
|
|
|
|
|