Skip to content
Discussion options

You must be logged in to vote

Viem does have structured errors — they all extend BaseError and carry machine-readable data. The trick is using the .walk() method to traverse the error chain.

Error structure

Every viem error is a BaseError with:

  • shortMessage — one-liner summary
  • details — raw RPC error string
  • metaMessages — array of contextual lines
  • name — error class name (e.g., ContractFunctionExecutionError)
  • .walk() — traverses the cause chain to find a specific error type

Catching and inspecting errors

import {
  BaseError,
  ContractFunctionRevertedError,
  ContractFunctionExecutionError,
  EstimateGasExecutionError,
  InsufficientFundsError,
} from 'viem';

try {
  await client.simulateContract({ ... });
} catch (

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@2wheeh
Comment options

Answer selected by 2wheeh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants