Skip to main content

atLatestBlock

A builder function that returns a partial interaction to query the latest block with the given finality state.

Use with other interactions like 'fcl.getBlock()' to get the latest block information. Block finality determines whether you get the latest executed block or the latest sealed block.

  • Executed blocks (soft-finality): Latest block that has been executed but may not be final
  • Sealed blocks (hard-finality): Latest block that has been sealed and is considered final

Import

You can import the entire package and access the function:


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

Or import directly the specific function:


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

Usage


_24
import * as fcl from '@onflow/fcl';
_24
_24
// Get latest executed block (soft finality)
_24
await fcl.send([fcl.getBlock(), fcl.atLatestBlock()]).then(fcl.decode);
_24
_24
// Get latest sealed block (hard finality)
_24
await fcl.send([fcl.getBlock(), fcl.atLatestBlock(true)]).then(fcl.decode);
_24
_24
// Get account from latest sealed block
_24
await fcl
_24
.send([fcl.getAccount('0x1d007d755706c469'), fcl.atLatestBlock(true)])
_24
.then(fcl.decode);
_24
_24
// Execute script against latest executed block
_24
await fcl
_24
.send([
_24
fcl.script`
_24
access(all) fun main(): UFix64 {
_24
return getCurrentBlock().height
_24
}
_24
`,
_24
fcl.atLatestBlock(),
_24
])
_24
.then(fcl.decode);

Parameters

isSealed (optional)

  • Type: boolean
  • Description: Block finality state, defaults to latest executed block ("soft-finality"), set to true for sealed blocks ("hard-finality")

Returns


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

A function that processes a partial interaction object


Rate this page