Skip to main content

Scanning Blocks

To implement a simple function to wait for a given block:

async function waitForBlock(blockHeight: number) {
let latestBlock = (await networkStatus()).current_block_identifier.index
while (true) {
if (blockHeight <= latestBlock)
return await block(blockHeight)
await sleep(10000)
latestBlock = (await networkStatus()).current_block_identifier.index
}
}

It can be used to scan blocks like this:

let latestBlockHeight = (await network_status()).current_block_identifier.index
while (true) {
const lastBlock = waitForBlock(latestBlockHeight)

# some processing according to business logic

latestBlockHeight += 1
}