# error_selector_json

Returns the 4-byte selector for a custom error described by JSON ABI; use it to identify revert payloads.

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

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

Returns the 4-byte selector for a custom error described by JSON ABI; use it to identify revert payloads.

## Overload 1: error_selector_json(JSON)

```sql
error_selector_json(JSON)
```

Builds the canonical custom error signature from JSON ABI inputs before hashing with Keccak-256.

- Kind: scalar
- Execution context: Offline
- Behavior: Canonical Json Error Selector
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `abi` (JSON; required; positional) — A single custom error ABI object with name and inputs.

### Returns

Custom error selector

First four bytes of the canonical error signature's Keccak-256 hash.

- `selector` (BYTES4)

Custom error selector. First four bytes of the canonical error signature's Keccak-256 hash.

### Examples

_Local SQL · Local_

```sql
-- Selector of the OpenZeppelin ERC20InsufficientBalance error
SELECT error_selector_json(json('{
    "type": "error",
    "name": "ERC20InsufficientBalance",
    "inputs": [
        {"name": "sender", "type": "address"},
        {"name": "balance", "type": "uint256"},
        {"name": "needed", "type": "uint256"}
    ]
}')) AS selector;
-- e450d38c
```

## Guidance

### Selector, topic0, calldata, and return data

Use error_selector or error_selector_json to match revert data selectors before decoding or classifying custom errors. The JSON helper derives canonical input types and ignores parameter names.

- Canonical signatures omit parameter names and spaces.
- Use function_selector for calldata selectors.
- Use event_signature for event topic0.

```sql
SELECT error_selector('InsufficientBalance(uint256,uint256)') AS selector;
```

## Related functions

- [error_decode_json](/docs/functions/error_decode_json.md) — Usually Before
- [evm_decode_revert_for](/docs/functions/evm_decode_revert_for.md) — See Also
