26

After beeing able to check account balances, I am looking for a method to list all transactions for a given Ethereum account through json-rpc protocol. I haven't found any method suitable for that on https://github.com/ethereum/wiki/wiki/JSON-RPC .

Similar to https://etherscan.io/txs?a=0xbb9bc244d798123fde783fcc1c72d3bb8c189413 I am trying to build an explorer that shows all transactions from a given account.

At How can all transactions sent to an address be found? a similar question is asked but I am not looking for a solution through a third party, but by querying directly to my ethereum node through json-rpc protocol.

Am I missing something? Is that possible to do through the json-rpc interface?

  • 1
    My hunch is that they index externally the transactions along this from property. There are a ton of other indices to be built actually. Can you add a link to your code? Sounds like an interesting project. – Xavier Leprêtre B9lab Sep 6 '16 at 15:42
15

If you want to build a explore like etherscan.io, you need to crawl all data in ethereum network and save all txs in the db.

There is no direct rpc method to obtain all transactions related to the account.

  • Why crawl and save into db again? ethereum clients already maintain their db. We just need to have API to get that data out. So it would be better to choose ethereum client of choice and add desired API. – Ayushya Mar 6 '19 at 19:18
4

The accepted answer to How can all transactions sent to an address be found? does not involve a third party.

The script in the answer uses the Web3 Javascript API which:

Under the hood it communicates to a local node through RPC calls. web3.js works with any Ethereum node, which exposes an RPC layer.

For example, where the script does:

var block = eth.getBlock(i, true);

you can use JSON-RPC eth_getBlockByNumber

Returns information about a block by block number.

Parameters

  1. QUANTITY|TAG - integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
  2. Boolean - If true it returns the full transaction objects, if false only the hashes of the transactions.

The Javascript API makes it easier than issuing JSON-RPC requests, but you can port the script to another language and issue JSON-RPC requests. Additionally, take note of the comment on the accepted answer that you will need more than a script to get "internal transactions".

  • So do you mean that to find out matching transactions (from or to a given address) I would need a script that full scans the entire blockchain? Is not the geth node capable of filtering out the matching transactions I am looking for? Aren't they indexed somehow on blockchain or the very node? Thx! – Juan Ignacio Pérez Sacristán Sep 7 '16 at 8:11
  • 3
    @JuanIgnacioPérezSacristán Nope, Ethereum didn't think this far ahead ;) – Sandwich Oct 23 '17 at 15:08
  • @JuanIgnacioPérezSacristán, Ethereum uses NoSQL database (LevelDB). It does not store table relations like a Relational Database. Using a Relational Database would impact performance because the amount of data is big. So, either you scan the entire DB or create a relational DB from the blockchain and query it with SQL. – Nulik Nov 27 '17 at 19:35
  • 1
    The amount of time required to parse all blocks for a given address is quite large. – nu everest Mar 9 '18 at 20:41
  • 1
    Yeah, but I need to get all transactions. Not just the one. – Melbourne Developer Jun 22 '18 at 2:51
0

Known Ethereum nodes lack functionality to get transaction list for ETH address (account).

To solve the issue, there is free and open source third-party solution — Ethereum transaction Indexer: 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 is written in Python. It works as a service in background:

  • connects to Ethereum node (works well with geth or parity, others are not tested)
  • stores all transactions in Postgres database (including smart contract transactions)
  • provides data for API to get transactions by address

Indexer connects to Ethereum node and fetches transactions using JSON RPC, creating transactions Index in Postgres database. First Indexer will store transactions starting from block you indicate. After that, it will check for new blocks every 20 seconds and update the index. You may change the interval.

API for Ethereum transaction Indexer is published by Postgrest tool. If you need to provide public API, use any webserver like nginx and setup proxy to Postgrest port in config.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.