Files
xrpl-dev-portal/_code-samples/non-fungible-token/py/list-nft-pages-and-offers.py
2024-05-29 16:12:05 -07:00

55 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from xrpl.models.requests.account_nfts import AccountNFTs
from xrpl.models import NFTBuyOffers
from xrpl.clients import JsonRpcClient
# This code sample lists an accounts NFT pages (https://xrpl.org/nftokenpage.html#nftokenpage)
# and see token offers for that accounts NFTs
# https://xrpl.org/non-fungible-tokens.html#nfts-on-the-xrp-ledger
# https://xrpl.org/nftokenpage.html#nftokenpage
# https://xrpl.org/nft_buy_offers.html#nft_buy_offers
# Testnet example: rP7aApVAyf3bjtRVVTixVSHBbU4kpd742k
account = input("Enter wallet address: ")
# Connect to a testnet node
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
client = JsonRpcClient(JSON_RPC_URL)
# Query the account's NFTs
response = client.request(
AccountNFTs(account=account)
)
if response.status[0:7] == "success":
nft_list = response.result['account_nfts']
# Only append the NFTs' NFT ID onto the nft_keylets list, other fields aren't needed
nft_keylets = []
for x in nft_list:
nft_keylets.append(x['NFTokenID'])
# Query through the NFTs' buy Offers
# For each NFT owned by the account (on nft_keylets), go through all their respective buy Offerss
for nft in nft_keylets:
response = client.request(
NFTBuyOffers(
nft_id=nft
)
)
offer_objects = response.result
if 'error' not in offer_objects:
print(f"\nBuy Offers for NFT {nft}:")
x_int = 1
for x in offer_objects['offers']:
print(f"\n{x_int}.")
print(f" NFT Offer Index: {x['nft_offer_index']}")
print(f" Offer Amount: {x['amount']} drops")
print(f" Offer Owner: {x['owner']}")
x_int += 1
else:
print(f"\nNFT {nft} does not have any buy offers...")
else:
print(f"Account {account} does not own any NFTs!")