fetchUintToBuffLe
Calls the pox-5 uint-to-buff-le read-only and returns n as 1 or 2 little-endian bytes. pox-5 uses it for the length prefix in script pushes.
Usage
import { bytesToHex } from '@stacks/common';
import { fetchUintToBuffLe } from '@stacks/bitcoin-staking';
bytesToHex(await fetchUintToBuffLe({ n: 1, network: 'mainnet' })); // '01'
bytesToHex(await fetchUintToBuffLe({ n: 256, network: 'mainnet' })); // '0001'Notes
Wraps
uint-to-buff-le. Values below 256 return 1 byte; values from 256 to 65,535 return 2 bytes.nabove 65,535 makes the contract panic, and the call throws.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 fetchUintToBuffLe(
opts: { n: number | bigint } & NetworkClientParam
): Promise<Uint8Array>;opts is a NetworkClientParam plus n.
Returns
Promise<Uint8Array>
n as 1 or 2 little-endian bytes.
Parameters
opts.n (required)
Type:
number | bigint
Non-negative integer, at most 65,535. Sent as a Clarity uint.
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?