0

I'm trying to get logs on ethers however, right now I'm chunking out the blocks based on the max blocks my provider allows (3500). However this is inefficient and slow, (Note: yes I know the graph probably would be better)

let fromBlock = parseInt(filter.fromBlock as any) ?? 0
let toBlock = parseInt((filter.toBlock ?? blockNumber) as any)
let blockSpan = toBlock - fromBlock;
const numberOfChunks = Math.ceil(blockSpan / MAX_BLOCKS_PER_LOG);

var logPromises = Array.apply(0, Array(numberOfChunks)).map((_,i) => {
  const fb = fromBlock + (i * MAX_BLOCKS_PER_LOG)
  //Logs filter is inclusive so we need to subtract 1
  const tb = Math.min(toBlock, fb + MAX_BLOCKS_PER_LOG - 1)
  return provider.getLogs({
    ...filter,
    fromBlock: fb,
    toBlock: tb,
  })
});
//...

I would like to lets say I would like to getLogs as block [315536, 355536, 392301], I know I can make requests to get logs for each individual block, however I would like to make a single query, so I don't have to make that many additional requests to the rpc provider.

Is this possible?

Ritzy Dev
  • 387
  • 3
  • 10

0 Answers0