[英]Best way to download all historic Ethereum ERC721 transfers
我想下载给定合约地址下代币的所有转账事件。
我知道 etherscan 为此提供了一个 API 端点,但它仅限于最近的 10,000 次传输(即使分页)。 https://docs.etherscan.io/api-endpoints/accounts#get-a-list-of-erc721-token-transfer-events-by-address
是否有第三方可以提供这些数据,或者我唯一的选择是直接从节点(Infura、Geth 等)获取它吗?
谢谢!
每份合约限制为 10k 次转账? 我知道 opensea events api 可以按合约地址 + 令牌 id 进行过滤,你可以在时间戳之前和之后进行过滤。 但我不知道他们走了多远。
这应该工作。 您需要在主函数中插入您的 API 密钥 (API_KEY) 和您想要探索的钱包地址。 输出将作为名为 data.csv 的 CSV 文件
from requests import get
import pandas as pd
pd.options.display.max_columns = 60 ## 0 by default
pd.options.display.width = 10000 ## 80 by default
pd.options.display.max_rows = 3000
API_KEY = ""
'''
https://api.etherscan.io/api
?module=account
&action=balance
&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae
&tag=latest
&apikey=YourApiKeyToken
'''
BASE_URL = "https://api.etherscan.io/api"
ETH_VALUE = 10 ** 18
def make_api_url(module, action, adress, **kwargs):
url = f"{BASE_URL}?module={module}&action={action}&address={adress}&apikey={API_KEY}"
for key, value in kwargs.items():
url += f"&{key}={value}"
return url
class Collector:
def __init__(self, start_block):
self.start_block = start_block
def get_erc721_transactions(self, adress):
'''
https://api.etherscan.io/api
?module=account
&action=tokennfttx
&contractaddress=0x06012c8cf97bead5deae237070f9587f8e7a266d
&address=0x6975be450864c02b4613023c2152ee0743572325
&page=1
&offset=100
&startblock=0
&endblock=27025780
&sort=asc
&apikey=YourApiKeyToken
'''
get_transaction_url = make_api_url("account",
"tokennfttx",
adress,
startblock=self.start_block,
endblock=999999999999999999,
sort='asc')
response = get(get_transaction_url)
data = response.json()
temp_df = pd.json_normalize(data['result'], sep="_")
temp_df['gasCost'] = temp_df.gasUsed.astype(float) * temp_df.gasPrice.astype(float)
print(temp_df.tail())
print(self.start_block)
temp_df['type'] = 'erc721'
return temp_df
def aggrigate_data(self, address):
data = pd.DataFrame()
self.start_block = 0
while True:
df = self.get_erc721_transactions(address)
if df.shape[0] == 0:
print('There is no erc721 transactions')
break
if self.start_block == df.blockNumber.iloc[-1]:
break
data = pd.concat([data, df])
self.start_block = df.blockNumber.iloc[-1]
data.head()
data.to_csv("data.csv")
if __name__ == '__main__':
'''Insert the wallet address you want to check'''
address = "0x4c8CFE078a5B989CeA4B330197246ceD82764c63"
Collector(0).aggrigate_data(address)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.