fetchAmountDelegatedForSigner
Reads the total micro-STX delegated to a signer-manager for one reward cycle, from protocol bonds and STX-only staking. Wraps the pox-5 read-only get-amount-delegated-for-signer, which reads the signer-delegated-per-cycle map.
Usage
import { fetchAmountDelegatedForSigner, fetchPoxInfo, fetchSignerSetFirstItem } from '@stacks/bitcoin-staking';
const { rewardCycleId: rewardCycle } = await fetchPoxInfo({ network: 'mainnet' });
// Any signer-manager in this cycle's signer set
const signerManager = await fetchSignerSetFirstItem({ rewardCycle, network: 'mainnet' });
if (signerManager) {
const ustx = await fetchAmountDelegatedForSigner({ signerManager, rewardCycle, network: 'mainnet' });
}Notes
The contract comment says this value should determine signer weight when approving blocks (signer-delegated-per-cycle).
A signer-manager joins the cycle's signer set when this reaches 50,000 STX (
SIGNER_SET_MIN_USTX, 50,000,000,000 micro-STX) and leaves it when it falls below (SIGNER_SET_MIN_USTX, add-staker-to-signer-for-cycle, remove-staker-from-signer-for-cycle). fetchSignerSetContainsForCycle reads the membership directly.Returns
0nwhen the contract has no entry for the inputs.A non-2xx response throws an
Errorwhose message starts withError calling read-only function.and includes the status code and URL. If the node reports that the call failed, theErrormessage is the node'scause.
Signature
opts is a NetworkClientParam plus signerManager and rewardCycle.
Returns
Promise<bigint>
Resolves to an amount in micro-STX.
Parameters
opts.signerManager (required)
Type:
string
Contract principal of the signer-manager, in the form <address>.<contract-name>. pox-5 keys signer state by this principal.
opts.rewardCycle (required)
Type:
number
Reward cycle to read.
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?