3

I'm currently developing a Java application which communicates with Geth using JSON-RPC.

I managed to implement something like @rustyx suggested on this thread using an HTTP connection, but it's too slow.
On my machine, the time to retrieve all the transactions for an account in a 1000 blocks range is approximately 100 seconds.

I know Etherscan's API is able to return the last 10'000 transactions made by an account, but you will need a API key and you have limited requests per day. Using an indexer could do the trick, but it's heavy and quite complex to implement.

So, i was wondering, is there any efficient way to retrieve all the transactions for a given account through a series of JSON-RPC requests? Is it possible to implement by myself a eth_listTransactions method? Could using a lower level programming language (like C) reduce the processing time?

Note: With 'addresses' I'm referring to wallet addresses, not contracts addresses.

Mattia Monari
  • 63
  • 2
  • 5

2 Answers2

0

you can use getPastEvents for the Transfer event and also specify block range from first block to latest

js version:

      const latest = await web3.eth.getBlockNumber(),
      contract = new web3.eth.Contract(abi, contractAddress),
      logs = await contract.getPastEvents(
                "Transfer", 
                {
                  fromBlock: 0,
                  toBlock: latest,
                  filter:
                     eventType === EventType.send ?
                                { from: address } : { to: address },
                 }
              );
Tashun Sandaru
  • 518
  • 2
  • 14
Mohammad
  • 106
  • 4
  • I think this will work just for contract addresses, not for wallet ones. – Mattia Monari Mar 16 '22 at 09:25
  • The proposed approach is just working for contracts and not general accounts. The question seems to be a duplicate, see also here https://ethereum.stackexchange.com/questions/8900/how-to-get-transactions-by-account-using-web3-js – Markus Sprunck Mar 20 '22 at 00:01
0

This is not a "native" RPC method but Alchemy does the job with the endpoint alchemy_getAssetTransfers. If you want the raw transactions (logs) you can get the txn hashes from that endpoint and later call eth_getTransactionByHash and/or eth_getTransactionReceipt for each txn hash. You will need to register but the free account is still pretty good and you won't need to iterate over blocks. The speed will depend on your internet connection and if you use concurrent requests. It's not CPU/memmory intensive so I don't think that using C will improve the performance.