Ethers.js: Listing all transactions of a wallet

Created on 30 Oct 2018  路  14Comments  路  Source: ethers-io/ethers.js

Hello. My intentions are to list all balance changes of a particular wallet (address provided).

this.provider.resetEventsBlock(0);
this.provider.on(this.wallet.address, (balance) => {
  console.log('New Balance: ' + balance);
});

However this callback is never called. Is there a reason why?

discussion

Most helpful comment

I鈥檝e used getHistory for quite a while in production wallets, without any obvious throttling issues, but it is a concern I have. It鈥檚 hard to know whether any of my users have been throttled in the wild though. And if Etherscan ever dials up throttling it could be an issue.

I鈥檝e been building out some libraries to help mitigate this and will be sharing them, but it is certainly non-trivial...

All 14 comments

The address event type cannot be used for historic information, unfortunately. This is restriction with the indexed data available on-chain.

Fortunately, Etherscan supports what you are trying to accomplish. :)

let provider = new ethers.providers.EtherscanProvider();
let history = await provider.getHistory(address);

This is possible because Etherscan has independently indexed all this data in their own, much more complex DB.

Let me know if you have any issues with this method. :)

@ricmoo thanks for reply, however this kinda feels sub-optimal (it does work what I want)

~This searches for all history related to given address. But this operation will be part of the larger procedure that will be run multiple times per day (imagine clearing in banks). And as history grows it will become harder to filter relevant data from history. How to tackle this issue?~

reading the docs helped, forget my ignorance... Cheers

Oh, the getHistory(address [ , fromBlock [ , toBlock ] ] ) command lets you filter further by block numbers. :)

I agree it isn鈥檛 ideal, but the data isn鈥檛 actually indexed in the node, so access to it isn鈥檛 really available, even passing a block height into the getBalance call. :s

Oh! Haha. Good timing. :)

Im going to close this now, but if you have any more issues, please feel free to re-open.

Thanks! :)

too bad that it doesn't support ropsten!

@Amirhb It should support Ropsten. What address are you using? I鈥檝e used it on Ropsten.

@ricmoo I just instantiated ethers and used the code snippet you mentioned above. The history fetched out from the mainnet. Am I missing something?

@Amirhb Oh, well yes; the above sample connects to mainnet. :)

To connect to Ropsten, use:

// This is the important part -------------------------v
let provider = new ethers.providers.EtherscanProvider("ropsten");
let history = await provider.getHistory(address);

For more info, check out the documentation for the Providers. And let me know if you have any other issues.

@ricmoo Thank you so much

@ricmoo Has anyone had any issues with EtherscanProvider().getHistory() such as API rate limiting ?

Looking to use the default EtherscanProvider() to retrieve wallet transactions but concerned etherscan will hit rate limit.

Is there an alternative to etherscan for transaction history?

I鈥檝e used getHistory for quite a while in production wallets, without any obvious throttling issues, but it is a concern I have. It鈥檚 hard to know whether any of my users have been throttled in the wild though. And if Etherscan ever dials up throttling it could be an issue.

I鈥檝e been building out some libraries to help mitigate this and will be sharing them, but it is certainly non-trivial...

In 5.4, where to find the doc for provider.getHistory(address)? I am looking for a method to pull out transactions for an account (address) within a period of time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jochenonline picture jochenonline  路  3Comments

pcowgill picture pcowgill  路  3Comments

GFJHogue picture GFJHogue  路  3Comments

dave-dm picture dave-dm  路  3Comments

PhABC picture PhABC  路  3Comments