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


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

Parameters

isSealed (optional)

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

Returns

InteractionBuilderFn


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


Rate this page