fetchPushScriptBytes
Calls the pox-5 push-script-bytes read-only and returns the input bytes prefixed with the Bitcoin Script push opcode that pox-5 uses when it builds a lockup script.
Usage
import { bytesToHex } from '@stacks/common';
import { fetchPushScriptBytes } from '@stacks/bitcoin-staking';
const pushed = await fetchPushScriptBytes({
bytes: '02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc',
network: 'mainnet',
});
bytesToHex(pushed); // '2102a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc'Notes
Wraps
push-script-bytes. The prefix depends on the input length: under 76 bytes, a single length byte; under 256 bytes,0x4c(OP_PUSHDATA1) and a 1-byte length; otherwise0x4d(OP_PUSHDATA2) and a 2-byte little-endian length.The input is at most 1,024 bytes, the contract's
(buff 1024)argument type.The SDK applies the same encoding locally when it builds a lockup script. Call this to cross-check that encoding against the deployed contract.
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 bytes.
Returns
Promise<Uint8Array>
The push opcode and length prefix, followed by the input bytes.
Parameters
opts.bytes (required)
Type:
Uint8Array | string
The data to push, as raw bytes or hex. At most 1,024 bytes.
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?