decodeErrorResult โ
Decodes reverted error from a contract function call.
Install โ
ts
import { decodeErrorResult } from 'viem'
Usage โ
ts
import { decodeErrorResult } from 'viem'
const value = decodeErrorResult({
abi: wagmiAbi,
data: '0xb758934b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000'
})
// { errorName: 'InvalidTokenError', args: ['sold out'] }
ts
export const wagmiAbi = [
...
{
inputs: [
{
name: "reason",
type: "string"
}
],
name: "InvalidTokenError",
type: "error"
},
...
] as const;
ts
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
export const publicClient = createPublicClient({
chain: mainnet,
transport: http()
})
Return Value โ
The decoded error.
Parameters โ
abi โ
- Type:
Abi
The contract's ABI.
ts
const value = decodeErrorResult({
abi: wagmiAbi,
data: '0xb758934b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000'
})
data โ
- Type:
Hex
The calldata.
ts
const value = decodeErrorResult({
abi: wagmiAbi,
data: '0xb758934b000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000'
})