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
Name | Description |
---|---|
AbiError.decode | ABI-decodes the provided error input (inputs ). |
AbiError.encode | ABI-encodes the provided error input (inputs ), prefixed with the 4 byte error selector. |
AbiError.format | Formats an AbiError.AbiError into a Human Readable ABI Error. |
AbiError.from | Parses an arbitrary JSON ABI Error or Human Readable ABI Error into a typed AbiError.AbiError . |
AbiError.fromAbi | Extracts an AbiError.AbiError from an Abi.Abi given a name and optional arguments. |
AbiError.getSelector | Computes the 4-byte selector for an AbiError.AbiError . |
Types
Name | Description |
---|---|
AbiError.AbiError | Root type for an AbiItem.AbiItem with an error type. |
AbiError.ExtractNames | |
AbiError.FromAbi | Extracts an AbiError.AbiError item from an Abi.Abi , given a name. |
AbiError.Name | Extracts the names of all AbiError.AbiError items in an Abi.Abi . |