Skip to main content

getBlockHeader

A builder function that returns the interaction to get a block header.

A block header contains metadata about a block without the full transaction details, making it more lightweight than fetching the entire block. This is useful when you only need block metadata like timestamp, height, parent hash, etc.

Use with 'fcl.atBlockId()' and 'fcl.atBlockHeight()' when building the interaction to get headers for specific blocks.

Import

You can import the entire package and access the function:


_10
import * as sdk from '@onflow/sdk';
_10
_10
sdk.getBlockHeader(isSealed);

Or import directly the specific function:


_10
import { getBlockHeader } from '@onflow/sdk';
_10
_10
getBlockHeader(isSealed);

Usage


_20
import * as fcl from '@onflow/fcl';
_20
_20
// Get latest sealed block header
_20
const sealedHeader = await fcl
_20
.send([fcl.getBlockHeader(true)])
_20
.then(fcl.decode);
_20
_20
console.log('Block height:', sealedHeader.height);
_20
console.log('Block timestamp:', sealedHeader.timestamp);
_20
console.log('Parent block ID:', sealedHeader.parentId);
_20
_20
// Get header for specific block
_20
const blockHeader = await fcl
_20
.send([fcl.getBlockHeader(), fcl.atBlockHeight(12345)])
_20
.then(fcl.decode);
_20
_20
// Get latest finalized block header
_20
const finalizedHeader = await fcl
_20
.send([fcl.getBlockHeader(false)])
_20
.then(fcl.decode);

Parameters

isSealed (optional)

  • Type: boolean
  • Description: Block finality state, true for sealed blocks, false for finalized blocks, null for latest

Returns


_10
export type InteractionBuilderFn = (
_10
ix: Interaction,
_10
) => Interaction | Promise<Interaction>;

A function that processes an interaction object


Rate this page