Developer Fundamentals

2. Blocks & Beats

Monitor new blocks and use Bloom filters to detect specific address activity efficiently.

Prerequisites

The Heartbeat 💓

Every time a new block is added to the blockchain, the network sends out a pulse. On VeChainThor, this happens approximately every 10 seconds.

Note: VeChainThor has officially transitioned its consensus mechanism to Delegated Proof of Stake (DPoS) to ensure sustainable and decentralized agreement.

Sometimes, you don't need a full block's worth of data—you just want to know if anything happened for a specific address. For that, we use Beats.

Think of Beats like a summary notification on your phone. It’s tiny, fast, and uses a Bloom Filter to tell you if a specific account was involved in that block.

On-chain vs off-chain works like...

a high-speed scanner. The Bloom filter provides a lightweight way to check for potential interactions without downloading every transaction receipt.


import { bloomUtils } from '@vechain/sdk-core';

// Check if our address had any interaction in this block heartbeat
const interactionFound = bloomUtils.isAddressInBloom(block.bloom, block.k, addressToTest);

if (interactionFound) {
    console.log("Something interesting happened! Time to look closer.");
}
import { bloomUtils } from '@vechain/sdk-core';

// Check if our address had any interaction in this block heartbeat
const interactionFound = bloomUtils.isAddressInBloom(block.bloom, block.k, addressToTest);

if (interactionFound) {
    console.log("Something interesting happened! Time to look closer.");
}
import { bloomUtils } from '@vechain/sdk-core';

// Check if our address had any interaction in this block heartbeat
const interactionFound = bloomUtils.isAddressInBloom(block.bloom, block.k, addressToTest);

if (interactionFound) {
    console.log("Something interesting happened! Time to look closer.");
}

Nice! This covers everything from the Gas Payer to the emitters of events. By using these "beats," you reduce the data your app needs to load, making it lightning-fast for your users. You’re a master of real-time data! 🏆