[英]Is there any way to get the sale status of an NFT (listed on marketplaces like OpenSea) using their contract address?
[英]Trying to print all owners of an NFT collection on OpenSea using API and Python 3
我想在 Opensea.io 上獲取 Aethir Wars 收藏的所有者列表。 我想要所有者,他們持有的 NFT,以及他們的 ETH 地址。 我可以獲得一長串所有者及其地址,但由於某種原因,該列表並不完整。 另外,我必須添加一個 if 語句,因為如果 NFT 被轉移而不是購買,則“Last_Sale”參數為空。 任何幫助表示贊賞。
import requests
url = "https://api.opensea.io/api/v1/assets"
api_key = "api key"
col = 'reapers'
def print_owners(race, offset):
querystring = {'order_by': 'name', 'order_direction': 'asc', 'offset': offset, 'limit': '50',
'collection': col, 'X-API-KEY': api_key}
response = requests.get(url, params=querystring)
data = response.json()
i = 0
for each_asset in data['assets']:
try:
if race in data['assets'][0]['name']:
if data["assets"][i]["last_sale"] is None:
print(data["assets"][i]["name"] + ': '
+ data["assets"][i]["sell_orders"][0]["maker"]["address"])
else:
print(data["assets"][i]["name"] + ': '
+ data["assets"][i]["last_sale"]["transaction"]["from_account"]["user"]["username"])
except TypeError:
pass
i += 1
x = range(0, 600, 50)
for stuff in x:
try:
print_owners(race='Reaper', offset=str(stuff))
except KeyError:
pass
try:
print_owners(race='Android', offset=str(stuff))
except KeyError:
pass
try:
print_owners(race='Goblin', offset=str(stuff))
except KeyError:
pass
我發現了很多例子,其中任何 ["user"]["username"]['name'] 都是 Null。 如果您不處理 If == Null,則會引發異常。
我有一個使用 streamlit 似乎可以在 Python 中工作的示例。
問候,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.