# evm_decode_revert_for

Returns a revert diagnostic using the ABI registered locally for a chain, contract, and block; use it when ABI selection depends on contract context.

Canonical HTML: <https://determica.com/docs/functions/evm_decode_revert_for>

- Kind: scalar function
- Category: [Contracts and ABI](/docs/category/contracts-and-abi.md)
- Tags: Evm Encoding, ABI, Diagnostics, Evidence

Returns a revert diagnostic using the ABI registered locally for a chain, contract, and block; use it when ABI selection depends on contract context.

## Overload 1: evm_decode_revert_for(UBIGINT, ADDRESS, UBIGINT, BYTES)

```sql
evm_decode_revert_for(UBIGINT, ADDRESS, UBIGINT, BYTES)
```

Looks up ABI metadata for the contract context, then decodes the revert payload.

- Kind: scalar
- Execution context: Offline
- Behavior: Registry Backed Revert Diagnostic
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Local Catalog State
- Return shape: JSON
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Requirements

- registered_contract_abi

### Inputs

- `chain_id` (UBIGINT; required; positional) — Chain id used to resolve registered ABI metadata.
- `address` (ADDRESS; required; positional) — Contract address used to resolve registered ABI metadata.
- `block_number` (UBIGINT; required; positional) — Block number for ABI registry validity range selection.
- `revert_data` (BYTES; required; positional) — Raw revert bytes returned by a failed call.

### Returns

Contextual revert diagnostic JSON

Uses error_decode_json shapes; decoded custom errors add abi_label when the registration has a label.

- `diagnostic` (JSON)

Contextual revert diagnostic JSON. Uses error_decode_json shapes; decoded custom errors add abi_label when the registration has a label.

### Examples

_Local SQL · Local_

```sql
WITH registered AS MATERIALIZED (
  SELECT evm_register_contract_abi(
    1,
    '0x0000000000000000000000000000000000000510'::ADDRESS,
    '[{"type":"error","name":"ERC20InsufficientBalance","inputs":[{"name":"sender","type":"address"},{"name":"balance","type":"uint256"},{"name":"needed","type":"uint256"}]}]'::JSON,
    'OpenZeppelin ERC-20',
    20000000,
    20000000
  ) AS ok
)
SELECT evm_decode_revert_for(
  1,
  '0x0000000000000000000000000000000000000510'::ADDRESS,
  20000000,
  error_selector('ERC20InsufficientBalance(address,uint256,uint256)')::BYTES
    || evm_abi_word('0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472'::ADDRESS)::BYTES
    || evm_abi_word(500000000::UINT256)::BYTES
    || evm_abi_word(615568393::UINT256)::BYTES
) AS diagnostic
FROM registered
WHERE ok;
-- diagnostic.name = ERC20InsufficientBalance
```

## Guidance

### Decode with local contract context

The function reads only the current database's ABI registry. Validity endpoints are inclusive, and a NULL endpoint in a registration is unbounded.

- Register the ABI before decoding. Required NULL inputs propagate NULL.
- If no registration matches, built-in Error(string) and Panic(uint256) can still decode; other payloads return unknown with their raw selector and payload words.

## Related functions

- [evm_register_contract_abi](/docs/functions/evm_register_contract_abi.md) — Usually After
- [error_decode_json](/docs/functions/error_decode_json.md) — Alternative
