forked from nessshon/tonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_nft_by_owner.py
More file actions
44 lines (33 loc) · 1.56 KB
/
get_nft_by_owner.py
File metadata and controls
44 lines (33 loc) · 1.56 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
from pytonapi.rest import TonapiRestClient
from pytonapi.types import Network
from pytonapi.utils import raw_to_userfriendly
# TONAPI key — get one at https://tonconsole.com/
API_KEY = "YOUR_API_KEY"
# Target network — MAINNET or TESTNET
NETWORK = Network.MAINNET
# Owner address — fetch all NFTs belonging to this account
ACCOUNT_ID = "0:408da3b28b6c065a593e10391269baaa9c5f8caebc0c69d9f0aabbab2a99256b"
async def main() -> None:
async with TonapiRestClient(API_KEY, NETWORK) as tonapi:
# Fetch NFTs owned by the account
# limit: maximum number of items to return (up to 1000)
# Returns: paginated list of NFT items with metadata, collection info, and previews
result = await tonapi.accounts.get_account_nft_items(
account_id=ACCOUNT_ID,
limit=10,
)
for nft in result.nft_items:
# NFT address in bounceable user-friendly format
address = raw_to_userfriendly(nft.address, True)
print(f"NFT: {address}")
# Collection info — present if the NFT belongs to a collection
# Some NFTs are standalone and don't belong to any collection
if nft.collection:
col = raw_to_userfriendly(nft.collection.address, True)
print(f"Collection: {col}")
# Preview images — generated by TONAPI in multiple resolutions
# Available sizes: 5x5, 100x100, 500x500, 1500x1500
print(f"Preview: {nft.previews[0].url}")
if __name__ == "__main__":
import asyncio
asyncio.run(main())