fetchReverseBuff32
Calls the pox-5 reverse-buff32 read-only and returns a 32-byte buffer with its byte order reversed. pox-5 uses it to convert hashes between Bitcoin's internal byte order and display order.
Usage
import { bytesToHex } from '@stacks/common';
import { fetchReverseBuff32 } from '@stacks/bitcoin-staking';
const reversed = await fetchReverseBuff32({
input: '00112233445566778899aabbccddeeff0102030405060708090a0b0c0d0e0f10',
network: 'mainnet',
});
bytesToHex(reversed); // '100f0e0d0c0b0a090807060504030201ffeeddccbbaa99887766554433221100'Notes
Wraps
reverse-buff32.The input must be exactly 32 bytes. A shorter input makes the contract panic, and a longer one fails the
(buff 32)argument type. The call throws in both cases.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 input.
Returns
Promise<Uint8Array>
The 32 input bytes in reverse order.
Parameters
opts.input (required)
Type:
Uint8Array | string
The 32 bytes to reverse, as raw bytes or hex.
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?