Skip to main content

block

Query the network for block by id, height or get the latest block.

Block ID is SHA3-256 hash of the entire block payload. This hash is stored as an ID field on any block response object (ie. response from GetLatestBlock).

Block height expresses the height of the block on the chain. The latest block height increases by one for every valid block produced.

Import

You can import the entire package and access the function:


_10
import * as sdk from "@onflow/sdk"
_10
_10
sdk.block(options, opts)

Or import directly the specific function:


_10
import { block } from "@onflow/sdk"
_10
_10
block(options, opts)

Usage


_11
import * as fcl from "@onflow/fcl";
_11
_11
// Get latest block
_11
const latestBlock = await fcl.block(); // Get the latest finalized block
_11
const latestSealedBlock = await fcl.block({sealed: true}); // Get the latest sealed block
_11
_11
// Get block by ID (uses builder function)
_11
await fcl.send([fcl.getBlock(), fcl.atBlockId("23232323232")]).then(fcl.decode);
_11
_11
// Get block at height (uses builder function)
_11
await fcl.send([fcl.getBlock(), fcl.atBlockHeight(123)]).then(fcl.decode)

Parameters

options (optional)

  • Type: BlockQueryOptions

_10
interface BlockQueryOptions {
_10
sealed?: boolean
_10
height?: number
_10
id?: string
_10
}

opts (optional)

  • Type: object
  • Description: Optional parameters

Returns

Promise<Block>


Rate this page