For the complete documentation index, see llms.txt. This page is also available as Markdown.

Stream Finalized Blocks

Consume finalized XL1 blocks in order with resumable checkpoints.

finalizedBlockStreamFromGateway follows finalized blocks, verifies continuity, and supports resuming after a previously processed block hash.

import { finalizedBlockStreamFromGateway } from '@xyo-network/xl1-sdk'

const stream = await finalizedBlockStreamFromGateway(gateway, {
  after: savedCheckpoint,
})

try {
  for await (const { block } of stream.blocks({ after: savedCheckpoint })) {
    await processBlock(block)
    await saveCheckpoint(block)
  }
} finally {
  await stream.stop()
}

Save the checkpoint only after your application has durably processed the block. If processing fails, resume from the last successful checkpoint.

Last updated