Skip to content

Blocks and headers

BlockHeader and Block parse the 80-byte header and full serialised blocks, for example those returned by a node’s getblockheader and getblock RPCs with verbosity 0. The examples use the genesis block. For what the header fields mean, see the guide’s Proof-of-work page.

final header = BlockHeader.fromHex(genesisHeaderHex); // 80 bytes, hex
header.id; // 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
header.version; // 1
header.time; // 1231006505 (seconds since the epoch)
header.bits; // 486604799: the encoded difficulty target
header.nonce; // 2083236893
header.hasValidProofOfWork(); // true: the hash is below the target
header.getDifficulty(); // 1.0

header.id is the block hash, in the byte order that block explorers show.

final block = Block.fromHex(genesisBlockHex);
block.header!.time; // 1231006505
block.transactions!.length; // 1
block.transactions![0].isCoinbase(); // true
block.transactions![0].outputs[0].satoshis; // 5000000000: the 50 BTC block reward
block.validMerkleRoot(); // true: the Transactions match the header's merkle root

validMerkleRoot() recomputes the merkle root from the block’s Transactions, and compares it with the one in the header. MerkleBlock parses the filtered-block format that peers send in reply to Bloom-filtered requests.