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