# How to read a failed swap: decoding a revert with the error ABI

> Canonical: https://blazephoenix.xyz/learn/reading-a-revert/
> License: CC BY-NC-ND 4.0 (attribution + link) · © 2026 BlazePhoenix
> Updated: 2026-10-05

A failed swap returns a 4-byte error selector and ABI-encoded arguments, not a sentence. How Solidity custom errors are encoded, where to find the revert data, how to decode a BlazePhoenix revert with viem and the published errors ABI, and why many reverts are a guard protecting your trade.

A revert carries a 4-byte error selector followed by the error's arguments. To read it you need the contract's error definitions. BlazePhoenix publishes them at /api/abi?contract=errors and through the get_abi tool of its MCP server; decoding the revert data against that ABI turns the bytes into a named error.

## How custom errors are encoded

Solidity custom errors are encoded like function calls: the selector is the first four bytes of the keccak-256 hash of the error's signature, followed by the ABI-encoded arguments. Revert data starting with a selector your wallet does not know is not a wallet bug; it is an error the wallet has no dictionary for.

The 4 bytes come from hashing the signature, for example ErrorName(uint16), so the same error has the same selector in every contract that declares it. Generic Error(string) and Panic(uint256) reverts use the selectors 0x08c379a0 and 0x4e487b71; anything else is a custom error that needs the declaring contract's ABI.

## Decode it

Any ABI-aware library works. With viem:

```
import { decodeErrorResult } from 'viem';

const { abi } = await (await fetch('https://blazephoenix.xyz/api/abi?contract=errors')).json();
const err = decodeErrorResult({ abi, data: '0x…' }); // the revert data
console.log(err.errorName, err.args);
```

## Where to find the revert data

The errors ABI response names the source revision it was generated from, so the dictionary matches the deployed code.

## A failure that protects you

Many reverts are the system working: a trade that would have received less than its minimum output is refused rather than filled badly. Decoding the error tells you which guard stopped the trade, so you change the input — size, slippage, route — instead of guessing.

**Verify it yourself:** curl -s 'https://blazephoenix.xyz/api/abi?contract=errors'

Related: https://blazephoenix.xyz/learn/why-a-refused-trade-is-good-news/ · https://blazephoenix.xyz/learn/minimum-output-explained/ · https://blazephoenix.xyz/learn/api-sdk-mcp/ · https://blazephoenix.xyz/learn/zero-rpc-mcp-server/ · https://blazephoenix.xyz/learn/contract-architecture/
