简体   繁体   English

如何通过地址获取以太坊交易列表

[英]How to get Ethereum transaction list by address

I'm looking for a way to get a list of transactions for a given address.我正在寻找一种方法来获取给定地址的交易列表。 If there are too many transactions I'd expect to be able to page the results.如果交易太多,我希望能够对结果进行分页。 It would be better if I can give the latest processed transaction as parameter so I could get the latest transactions from a given point.如果我可以将最新处理的交易作为参数给出,这样我就可以从给定点获取最新交易,那就更好了。

Something like this:像这样的东西:

var page = 1;
txList = getTransactionList("0x323432432...", page, lastProcessedTx);

From my research so far there is no way to get transaction list for an address.从我目前的研究来看,没有办法获得一个地址的交易列表。 You should check all the transactions in the blockchain for the given address or relate addresses to transaction hashes in a database.您应该检查给定地址的区块链中的所有交易,或者将地址与数据库中的交易哈希相关联。 See this thread that confirms the lack of the needed API: https://github.com/ethereum/go-ethereum/issues/1897请参阅此线程,确认缺少所需的 API: https : //github.com/ethereum/go-ethereum/issues/1897

An alternative to this is to use Etherscan API: https://etherscan.io/apis But it depends on a third party server.另一种方法是使用 Etherscan API: https ://etherscan.io/apis 但它依赖于第三方服务器。

Known Ethereum nodes lack functionality to get transaction list for ETH address (account).已知的以太坊节点缺乏获取 ETH 地址(帐户)交易列表的功能。

To solve the issue, there is free and open source third-party solution — Ethereum transaction Indexer: https://github.com/Adamant-im/ETH-transactions-storage为了解决这个问题,有免费开源的第三方解决方案——以太坊交易索引器: https : //github.com/Adamant-im/ETH-transactions-storage

The Indexer allows to explore transactions by Ethereum address and obtain a history of any user|wallet in just a move, like Etherscan does. Indexer 允许通过以太坊地址探索交易,并像 Etherscan 一样,只需移动即可获取任何用户|钱包的历史记录。 Indexer is written in Python.索引器是用 Python 编写的。 It works as a service in background:它在后台作为服务工作:

  • connects to Ethereum node (works well with geth or parity, others are not tested)连接到以太坊节点(适用于 geth 或 parity,其他未测试)
  • stores all transactions in Postgres database (including smart contract transactions)将所有交易存储在 Postgres 数据库中(包括智能合约交易)
  • provides data for API to get transactions by address为 API 提供数据以按地址获取交易

Indexer connects to Ethereum node and fetches transactions using JSON RPC, creating transactions Index in Postgres database. Indexer 连接到 Ethereum 节点并使用 JSON RPC 获取交易,在 Postgres 数据库中创建交易索引。 First Indexer will store transactions starting from block you indicate. First Indexer 将存储从您指定的区块开始的交易。 After that, it will check for new blocks every 20 seconds and update the index.之后,它将每 20 秒检查一次新块并更新索引。 You may change the interval.您可以更改间隔。

API for Ethereum transaction Indexer is published by Postgrest tool.以太坊交易索引器的 API 由 Postgrest 工具发布。 If you need to provide public API, use any webserver like nginx and setup proxy to Postgrest port in config.如果您需要提供公共 API,请使用任何网络服务器(如 nginx)并在 config 中设置代理到 Postgrest 端口。

After index is created, you can use requests like创建索引后,您可以使用类似的请求

curl -k -X GET "http://localhost:3000/?and=(contract_to.eq.,or(txfrom.eq.0x6b924750e56a674a2ad01fbf09c7c9012f16f094,txto.eq.0x6b924750e56a674a2ad01fbf09c7c9012f16f094))&order=time.desc&limit=25"

or

https://yourserver.com/ethtxs?and=(contract_to.eq.,or(txfrom.eq.0x6b924750e56a674a2ad01fbf09c7c9012f16f094,txto.eq.0x6b924750e56a674a2ad01fbf09c7c9012f16f094))&order=time.desc&limit=25

The request will show 25 last transactions for Ethereum address 0x6b924750e56a674a2ad01fbf09c7c9012f16f094, ordered by timestamp.该请求将显示以太坊地址 0x6b924750e56a674a2ad01fbf09c7c9012f16f094 的最后 25 笔交易,按时间戳排序。

您可以使用 etherscan.io API: https ://etherscan.io/apis#accounts 示例

Probably your best bet right now is to use https://www.covalenthq.com/docs/api/可能你现在最好的选择是使用https://www.covalenthq.com/docs/api/

As far as I know it is free to use with no rate limiting.据我所知,它可以免费使用,没有速率限制。 In your case example API request would look as follows:在您的示例 API 请求中,如下所示:

curl -X GET "https://api.covalenthq.com/v1/1/address/0x5a6d3b6bf795a3160dc7c139dee9f60ce0f00cae/transactions_v2/?&key=[YOUR_API_KEY]" \
 -H "Accept: application/json"

https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/transfers_v2/ https://www.covalenthq.com/docs/api/#get-/v1/{chain_id}/address/{address}/transfers_v2/

Fortunately, Geth EVM has new tools to get this done.幸运的是,Geth EVM 有新工具来完成这项工作。 It's possible to use debug_traceTransaction with RPC API.可以将 debug_traceTransaction 与 RPC API 一起使用。

In NodeJS:在 NodeJS 中:

var web3 = require('web3').web3;
web3.currentProvider.sendAsync({
    method: "debug_traceTransaction",
    params: ['0x3fac854179691e377fc1aa180b71a4033b6bb3bde2a7ef00bc8e78f849ad356e', {}],
    jsonrpc: "2.0",
    id: "2"
}, function (err, result) {
    ...
});

Then, you'll need to'CREATE', 'CALL', 'CALLCODE' and 'DELEGATECALL' opcodes and keep track of the stack.然后,您需要'CREATE'、'CALL'、'CALLCODE' 和'DELEGATECALL' 操作码并跟踪堆栈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM