Skip to content

AbiError Errors

AbiError.SelectorMismatchError

Thrown when the selector of the provided data does not match the selector of the error, or of one of its overloads.

Examples

import { AbiError } from 'ox'
 
const error = AbiError.from(
  'error Unauthorized(address account)'
)
 
AbiError.decode(
  error,
  '0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004626f6f6d00000000000000000000000000000000000000000000000000000000'
)
AbiError.SelectorMismatchError: Selector "0x08c379a0" does not match the expected selector "0x8e4a23d6".
Error: error Unauthorized(address account)
Selector: 0x8e4a23d6

Solution

Ensure that the data was encoded for the error, or pass the data to AbiError.fromAbi to resolve the error by its selector.

import { AbiError } from 'ox'
 
const error = AbiError.from(
  'error Unauthorized(address account)'
)
 
AbiError.decode(
  error,
  '0x8e4a23d6000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045'
)

Source: src/core/AbiError.ts