通过 Etherscan API 接收代币转账

问题描述 投票:0回答:1

我想接收特定代币的所有代币转账。例如,如果您打开该网址,它将在浏览器中显示 85 次传输:https://etherscan.io/token/0x2d8b6fc9ae0fa508caa14453ce13acb8d906c184

我已经发现,我可以获取合约的交易,在该示例中为 51:https://etherscan.io/address/0x2d8b6fc9ae0fa508caa14453ce13acb8d906c184

我可以通过以下 api 调用获取此信息 - 这不是我想要的,因为这为我提供了合约的交易: https://api.etherscan.io/api?module=account&action=txlist&address=0x2d8b6fc9ae0fa508caa14453ce13acb8d906c184&apikey=...

interface cryptocurrency etherscan
1个回答
0
投票

我通过moralis API找到了一个解决方案(免费版本,最多40k CU/天)- C#代码:

const string CURSOR_SUFFIX = @"&cursor=";
const string GET_TRANSACTIONS_P = @"https://deep-index.moralis.io/api/v2.2/erc20/";
const string GET_TRANSACTIONS_S = @"/transfers?chain=eth&order=ASC&limit=100";

private async Task<JsonResult> getTransactionPageForToken(string pContractAddress, string pCursor)
{
    JsonResult jrTokenTransactions;
    string sUrl = GET_TRANSACTIONS_P + pContractAddress + GET_TRANSACTIONS_S;

    if (pCursor != string.Empty)
    {
        sUrl += CURSOR_SUFFIX + pCursor;
    }

    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Add("X-API-Key", API_KEY_TOKEN);

        var response = await client.GetAsync(sUrl);
        response.EnsureSuccessStatusCode();
        string sContent = await response.Content.ReadAsStringAsync();

        jrTokenTransactions = JsonConvert.DeserializeObject<JsonResult>(sContent);
        Console.WriteLine(sContent);
    }

    return jrTokenTransactions;
}
© www.soinside.com 2019 - 2024. All rights reserved.