Skip to content

AbiError

Utilities & types for working with Errors on ABIs.

AbiError is a sub-type of AbiItem.

Examples

Below are some examples demonstrating common usages of the AbiError module:

Instantiating via JSON ABI

An AbiError can be instantiated from a JSON ABI by using AbiError.fromAbi:

import { Abi, AbiError } from 'ox'
 
const abi = Abi.from([
  'function foo()',
  'error BadSignatureV(uint8 v)',
  'function bar(string a) returns (uint256 x)',
])
 
const 
const item: { readonly name: "BadSignatureV"; readonly type: "error"; readonly inputs: readonly [...]; }
item
= AbiError.fromAbi(abi, 'BadSignatureV')

Instantiating via Human-Readable ABI Item

An AbiError can be instantiated from a human-readable ABI by using AbiError.from:

import { AbiError } from 'ox'
 
const error = AbiError.from('error BadSignatureV(uint8 v)')
 
const error: { readonly name: "BadSignatureV"; readonly type: "error"; readonly inputs: readonly [{ readonly type: "uint8"; readonly name: "v"; }]; }
error

Decoding Error Data

Error data can be ABI-decoded using the AbiError.decode function.

import { Abi, AbiError } from 'ox'
 
const abi = Abi.from([...])
const error = AbiError.fromAbi(abi, 'InvalidSignature')
 
const value = AbiError.decode(error, '0xecde634900000000000000000000000000000000000000000000000000000000000001a400000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001')
[420n, 69n, 1]

Functions

NameDescription
AbiError.decodeABI-decodes the provided error input (inputs).
AbiError.encodeABI-encodes the provided error input (inputs), prefixed with the 4 byte error selector.
AbiError.formatFormats an AbiError.AbiError into a Human Readable ABI Error.
AbiError.fromParses an arbitrary JSON ABI Error or Human Readable ABI Error into a typed AbiError.AbiError.
AbiError.fromAbiExtracts an AbiError.AbiError from an Abi.Abi given a name and optional arguments.
AbiError.getSelectorComputes the 4-byte selector for an AbiError.AbiError.

Types

NameDescription
AbiError.AbiErrorRoot type for an AbiItem.AbiItem with an error type.
AbiError.ExtractNames
AbiError.FromAbiExtracts an AbiError.AbiError item from an Abi.Abi, given a name.
AbiError.NameExtracts the names of all AbiError.AbiError items in an Abi.Abi.