With the indexer, you can go through a range of blocks and handle the transactions.
A range can be specified by block numbers or dates. The Indexer can also listen for incoming block headers and transactions.
import { BlocksTxIndexer } from '@dequanto/indexer/BlocksTxIndexer'
let indexer = new BlocksTxIndexer(platform, {
name: 'foo worker',
// loads also transactions from the mined blocks
loadTransactions: true,
// saves blockNumbers of already processed blocks
persistance: true,
});
indexer.onBlock(async (
client: Web3Client,
block: BlockTransactionString,
txs: Transaction[]
) => {
// process txs
});
// starts indexing from the block at specified date
// as no end date is provided, after indexer is ready, it will listen for incomming blocks
indexer.start(new Date('2022-04-22T00:00:00Z'));
// gets current status
let status = indexer.stats();