Developer Fundamentals

1. The Blockchain Heartbeat

Understand the structure of VeChainThor blocks and how to retrieve them using the SDK.

Prerequisites

The Pulse of the Network (Blocks)

Welcome to the lab! 🧪 To build a dApp, you first need to understand how the blockchain stores its "batch of changes." We call these Blocks.

On VeChainThor, a new block is generated approximately every 10 seconds, even if no transactions are published. Think of it like a steady heartbeat!

Important Update: VeChainThor recently upgraded its consensus to Delegated Proof of Stake (DPoS). It's more decentralized and sustainable than ever!

In JavaScript, we use the ThorClient to talk to the network. "Think of a block request like calling a library..." 📚

import { ThorClient } from '@vechain/sdk-network';
const thor = ThorClient.at('https://mainnet.vechain.org');

// Get a summary of a block
const compressed = await thor.blocks.getBlockCompressed('best');
import { ThorClient } from '@vechain/sdk-network';
const thor = ThorClient.at('https://mainnet.vechain.org');

// Get a summary of a block
const compressed = await thor.blocks.getBlockCompressed('best');
import { ThorClient } from '@vechain/sdk-network';
const thor = ThorClient.at('https://mainnet.vechain.org');

// Get a summary of a block
const compressed = await thor.blocks.getBlockCompressed('best');

NICE!

You used the alias "best" to get the latest block. You can also ask for "genesis" (Block 0) or "finalized" (the last irreversible block).

You’re getting it! There are two main ways to read a block:

  1. Compressed: Just the metadata and transaction IDs.

  2. Expanded: Everything, including the full details of every transaction and their receipts!

Almost there!