fetchProtocolBond
Calls the pox-5 get-protocol-bond read-only and returns a protocol bond's configuration, or undefined if setup-bond has not been called for that index.
Usage
import { fetchProtocolBond } from '@stacks/bitcoin-staking';
const bond = await fetchProtocolBond({ bondIndex: 1, network: 'mainnet' });
const isBondSetup = bond !== undefined;Notes
get-protocol-bondreturns(map-get? protocol-bonds bond-index), so the result matches fetchBond, which reads the map directly.fetchBondStatus calls this function to decide
isBondSetupwhen you do not pass it.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
function fetchProtocolBond(
opts: { bondIndex: number } & NetworkClientParam
): Promise<Bond | undefined>;opts is a NetworkClientParam plus bondIndex.
Returns
Promise<Bond | undefined>
Resolves to a Bond, or undefined when the contract returns none.
Parameters
opts.bondIndex (required)
Type:
number
Index of the protocol bond.
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?