fetchVerifyBlockHeader
Calls the pox-5 verify-block-header read-only and returns true if an 80-byte Bitcoin block header hashes to the burn block header hash the Stacks node records at a given height.
Usage
import { fetchVerifyBlockHeader } from '@stacks/bitcoin-staking';
declare const header: string; // 80-byte header hex, e.g. from Bitcoin Core `getblockheader <hash> false`
const ok = await fetchVerifyBlockHeader({
header,
burnHeight: 850000,
network: 'mainnet',
});Notes
Wraps
verify-block-header, which compares the byte-reversed double SHA-256 of the header withget-burn-block-info? header-hashatburnHeight.Returns
falsewhen the hashes differ and when the node has no header atburnHeight.register-for-bondruns the same check on each L1 lockup output'sheaderandheight, and fails withERR_INVALID_BTC_HEADER (u40)when it returnsfalse(L2089-L2091).Read the recorded hash itself with fetchBurnBlockHeaderHash.
Throws an
Errorif the node returns a non-2xx status (the message starts withError calling read-only function.) or answersokay: false(the message is the node'scause).
Signature
opts is a NetworkClientParam plus the fields below.
Returns
Promise<boolean>
true if the header matches the recorded hash at burnHeight, false otherwise.
Parameters
opts.header (required)
Type:
Uint8Array | string
The 80-byte block header, as raw bytes or hex.
opts.burnHeight (required)
Type:
number
Bitcoin block height the header should be at.
opts.network (optional)
Type:
StacksNetworkName | StacksNetwork
The network to query: a name such as 'mainnet' or 'testnet', or a StacksNetwork object. Defaults to 'mainnet'.
opts.client (optional)
Type:
{ baseUrl?: string; fetch?: FetchFn }
Overrides the API base URL or the fetch function, for example to query your own node. Fields you set replace the network's defaults.
Was this helpful?