簡體   English   中英

下載所有歷史以太坊 ERC721 傳輸的最佳方式

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM