For the complete documentation index, see llms.txt. This page is also available as Markdown.

fetchLastRewardComputeHeight

Reads the calculation height stored by the last calculate-rewards call: the Bitcoin block before the start of the distribution cycle it ran in. Wraps the pox-5 read-only get-last-reward-compute-height, which returns the last-reward-compute-height data-var.


Usage

import {
  currentDistributionCycle,
  distributionCycleToBurnHeight,
  fetchLastRewardComputeHeight,
  fetchPoxInfo,
} from '@stacks/bitcoin-staking';

const poxInfo = await fetchPoxInfo({ network: 'mainnet' });
const lastHeight = await fetchLastRewardComputeHeight({ network: 'mainnet' });

// The height calculate-rewards would use now
const calculationHeight =
  distributionCycleToBurnHeight({ distributionCycle: currentDistributionCycle(poxInfo), poxInfo }) - 1;
const pending = calculationHeight > lastHeight;

Notes


Signature


Returns

Promise<number>

Resolves to a Bitcoin block height as a number.


Parameters

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?