JavaScript theorytheory 0/50 · 0%
Web3 · hard

40. Events, logs and indexing

Querying history without a database.

Contract logs are queried by address, topics and block range. Providers cap the range, so page through it, and handle reorgs by re-reading recent blocks.

const logs = await c.queryFilter(c.filters.Staked(user), fromBlock, toBlock);

For anything beyond a few thousand blocks, index into your own store rather than querying the chain on every page load.

Check your understanding

  1. 1. What are logs filtered by?

  2. 2. Why page a block range?

  3. 3. What must an indexer handle?