|
import requests |
|
|
|
|
|
|
|
def get_nfts(wallet_address, end_index=1000): |
|
url = f"https://polygon-mainnet.g.alchemy.com/v2/{api_key}/getNFTs" |
|
params = { |
|
"owner": wallet_address, |
|
"withMetadata": "false" |
|
} |
|
|
|
token_ids = [] |
|
page_key = None |
|
|
|
while True: |
|
if page_key: |
|
params['pageKey'] = page_key |
|
|
|
response = requests.get(url, params=params) |
|
if response.status_code == 200: |
|
data = response.json() |
|
nfts = data.get('ownedNfts', []) |
|
token_ids.extend([int(nft['id']['tokenId'], 16) for nft in nfts]) |
|
|
|
page_key = data.get('pageKey') |
|
if not page_key: |
|
break |
|
else: |
|
print(f"Error fetching NFTs: {response.status_code}") |
|
break |
|
|
|
filtered_token_ids = [token_id for token_id in token_ids if token_id > 9] |
|
|
|
|
|
return filtered_token_ids[-end_index:] |
|
|
|
|
|
|
|
api_key = "4tRBr-iKmuEiV0wXmfHbrYPPCCd3cRDt" |
|
|
|
|
|
|
|
|
|
|