简体   繁体   中英

Web3 getting contract transactions history

I created simple monitor to check a contract and its latest transactions . I know I can get this information by getting latest block like:

block = await this.web3.eth.getBlock("latest");

and later on check if receiver is the same as contract that I am monitoring. But I would like to get history of that contract for example last 24 hours and see what transactions were made there. Is it possible to do that and if yes how can I achieve that?

You can specify a specific block number instead of the "latest" parameter - extract the number of the last block at some point and then iteratively reduce it by one until the desired depth of history is reached.

However, it would be more efficient to write an application that would read new blocks in resident mode as they appear on the network and write them to some database - in this case, the user could get information much faster and to an arbitrary depth.

At the same time, we must not forget to track possible forks with the cancellation of the corresponding transactions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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