Skip to content

decodeErrorResult

Decodes reverted error from a contract function call.

Install

import { decodeErrorResult } from 'viem'

Usage

example.ts
import { decodeErrorResult } from 'viem'
 
const value = decodeErrorResult({
  abi: wagmiAbi,
  data: '0xb758934b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000'
})
// { errorName: 'InvalidTokenError', args: ['sold out'] }

Return Value

The decoded error.

Parameters

abi

The contract's ABI.

const value = decodeErrorResult({
  abi: wagmiAbi, 
  data: '0xb758934b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000'
})

data

The calldata.

const value = decodeErrorResult({
  abi: wagmiAbi,
  data: '0xb758934b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000'
})