fetchTotalSharesStakedForCycle
Calls the pox-5 get-total-shares-staked-for-cycle read-only and returns the total shares in one reward cycle: sats for a protocol bond, micro-STX for STX-only staking.
Usage
import { fetchPoxInfo, fetchTotalSharesStakedForCycle } from '@stacks/bitcoin-staking';
const { rewardCycleId } = await fetchPoxInfo({ network: 'mainnet' });
// STX-only staking: micro-STX
const ustx = await fetchTotalSharesStakedForCycle({ rewardCycle: rewardCycleId });
// Protocol bond 1: sats
const sats = await fetchTotalSharesStakedForCycle({ rewardCycle: rewardCycleId, bondIndex: 1 });Notes
Reads the
total-shares-staked-for-cyclemap throughget-total-shares-staked-for-cycle. Returns0nwhen there is no entry.With
bondIndexthe value is sats; without it the value is micro-STX. The SDK sendsbondIndexas(some u<bondIndex>), ornonewhen you omit it.This is the denominator pox-5 divides each cycle's rewards by, for the STX-only staking tranche (L2192-L2200) and for each protocol bond (L2262, L2276-L2279).
register-for-bond,stakeandstake-updateadd to it;unstake,unstake-sbtcandannounce-l1-early-exitsubtract from it. For a per-bond figure thatregister-for-bondrecords, see fetchTotalSbtcStakedForBond.The micro-STX figure excludes STX locked in protocol bonds. It counts STX-only staking only for signer-managers with at least 50,000,000,000 micro-STX (50,000 STX,
SIGNER_SET_MIN_USTX) staked to them in that cycle (L1705-L1732). For all micro-STX staked in a cycle, use fetchTotalUstxStacked.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<bigint>
Total shares for the cycle: sats when bondIndex is set, micro-STX when it is omitted.
Parameters
opts.rewardCycle (required)
Type:
number
Reward cycle to read.
opts.bondIndex (optional)
Type:
number
Protocol bond index. Set it to read the bond's sats total; omit it to read the micro-STX total for STX-only staking.
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?