parsePox5Error
Extracts the N from an (err uN) contract result. Accepts a Clarity value, such as a read-only call's response, or the repr string the Stacks API reports for a transaction result. Pure computation.
Usage
import { Cl } from '@stacks/transactions';
import { describePox5Error, parsePox5Error } from '@stacks/bitcoin-staking';
parsePox5Error('(err u7)'); // 7
parsePox5Error(Cl.error(Cl.uint(40))); // 40
parsePox5Error('(ok true)'); // undefined
const code = parsePox5Error('(err u24)');
const info = code !== undefined ? describePox5Error(code) : undefined;
info?.name; // 'ERR_INVALID_START_BURN_HEIGHT'Notes
A string must match
(err u<digits>)after trimming whitespace. A Clarity value must be aResponseErrwrapping auint. Anything else returnsundefined, includingokresults andnullorundefinedinput.Any
(err uN)parses, whichever contract produced it. A pox-5 call can fail with the signer-manager's own error fromvalidate-stake!, whichregister-for-bond,update-bond-registration,stakeandstake-updatereturn throughtry!, or with the sBTC token's error whenregister-for-bondpulls sBTC from the staker. Read the number as a Pox5ErrorCode only when the error came from pox-5 itself.
Signature
Returns
number | undefined
The error number, or undefined if result is not an (err uN).
Parameters
result (required)
Type:
ClarityValue | string | undefined
A ClarityValue response, or the result's repr string. undefined is accepted and returns undefined.
Was this helpful?