Parse recent blocks
Safety: blockchain-query
This recipe shows the shape of a bounded blockchain parser. Use it when you want to inspect recent irreversible blocks without broadcasting anything.
For the complete workflow and production design notes, read Parse blockchain history.
ts
import { BlockchainMode, Client } from '@beblurt/dblurt';
const client = new Client(['https://rpc.blurt.blog']);
const irreversible = await client.blockchain.getCurrentBlockNum(BlockchainMode.Irreversible);
for await (const block of client.blockchain.getBlocks({
from: irreversible - 3,
to: irreversible - 1,
mode: BlockchainMode.Irreversible
})) {
console.log({
witness: block.witness,
transactions: block.transactions.length
});
}Validated examples:
examples/node/stream-block-numbers.cjsexamples/node/read-blocks-with-helper.cjsexamples/node/read-operations-with-helper.cjs
Why this is bounded
The parser uses an explicit from and to range so it finishes. Long-running parsers should persist checkpoints, handle retries deliberately and define whether they process irreversible or latest blocks.
Operation parsing variant
ts
for await (const operation of client.blockchain.getOperations({
from: irreversible - 3,
to: irreversible - 1,
mode: BlockchainMode.Irreversible
})) {
console.log(operation.op[0]);
}Use Handle errors for retry classification and RPC endpoints and failover for endpoint behavior.
