fetchBurnBlockHeaderHash
Calls the pox-5 get-bc-h-hash read-only and returns the Bitcoin block header hash the Stacks node records at a burn height, or undefined if it has none.
Usage
import { bytesToHex } from '@stacks/common';
import { fetchBurnBlockHeaderHash, fetchPoxInfo } from '@stacks/bitcoin-staking';
const { currentBurnchainBlockHeight } = await fetchPoxInfo({ network: 'mainnet' });
const hash = await fetchBurnBlockHeaderHash({
burnHeight: currentBurnchainBlockHeight - 5,
network: 'mainnet',
});
const hex = hash ? bytesToHex(hash) : undefined;Notes
Wraps
get-bc-h-hash, which returnsget-burn-block-info? header-hashfor the height.The hash is in the byte order fetchVerifyBlockHeader compares against: the double SHA-256 of the header, reversed.
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 burnHeight.
Returns
Promise<Uint8Array | undefined>
The 32-byte header hash, or undefined when the node has no header at burnHeight.
Parameters
opts.burnHeight (required)
Type:
number
Bitcoin block height to look up.
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?