Skip to content

AbiError.from

Parses an arbitrary JSON ABI Error or Human Readable ABI Error into a typed AbiError.AbiError.

Imports

Named
import { AbiError } from 'ox'

Examples

JSON ABIs

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

Human Readable ABIs

A Human Readable ABI can be parsed into a typed ABI object:

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

It is possible to specify structs along with your definitions:

import { AbiError } from 'ox'
 
const badSignatureVError = AbiError.from([
  'struct Signature { uint8 v; }',
  'error BadSignatureV(Signature signature)',
])
 
const badSignatureVError: { readonly name: "BadSignatureV"; readonly type: "error"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "uint8"; readonly name: "v"; }]; readonly name: "signature"; }]; }
badSignatureVError

Definition

function from<abiError>(
  abiError: (abiError | AbiError | string | readonly string[]) & ((abiError extends string ? internal.Signature<abiError> : never) | (abiError extends readonly string[] ? internal.Signatures<abiError> : never) | AbiError),
  options?: from.Options,
): from.ReturnType<abiError>

Source: src/AbiError.ts

Parameters

abiError

  • Type: (abiError | AbiError | string | readonly string[]) & ((abiError extends string ? internal.Signature<abiError> : never) | (abiError extends readonly string[] ? internal.Signatures<abiError> : never) | AbiError)

The ABI Error to parse.

options

  • Type: from.Options
  • Optional

options.prepare

  • Type: boolean
  • Optional

Whether or not to prepare the extracted function (optimization for encoding performance). When true, the hash property is computed and included in the returned value.

Return Type

Typed ABI Error.

from.ReturnType<abiError>