forked from nessshon/tonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_nft_by_collection.py
More file actions
42 lines (31 loc) · 1.45 KB
/
get_nft_by_collection.py
File metadata and controls
42 lines (31 loc) · 1.45 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
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
# NFT collection address — all items minted under this contract
COLLECTION_ID = "EQAUxYSo-UwoqAGixaD3d7CNLp9PthgmEZfnr6BvsijzJHdA"
async def main() -> None:
async with TonapiRestClient(API_KEY, NETWORK) as tonapi:
# Fetch NFT items from the collection
# limit: maximum number of items to return (up to 1000)
# Returns: paginated list of NFT items with metadata, owner, and previews
result = await tonapi.nft.get_items_from_collection(
account_id=COLLECTION_ID,
limit=100,
)
for nft in result.nft_items:
# NFT address in raw format (workchain:hex_hash)
# raw_to_userfriendly() converts to bounceable base64 form
address = raw_to_userfriendly(nft.address, True)
print(f"NFT: {address}")
# Owner address — who currently holds this NFT
print(f"Owner: {raw_to_userfriendly(nft.owner.address)}")
# 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())