# event_decode

Returns one EVM log as ABI-derived typed columns; use it when a constant event ABI can define the SQL schema at bind time.

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

- Kind: table function
- Category: [Contracts and ABI](/docs/category/contracts-and-abi.md)
- Tags: ABI, Logs, Typed, RPC

Returns one EVM log as ABI-derived typed columns; use it when a constant event ABI can define the SQL schema at bind time.

## Overload 1: event_decode(JSON, BYTES32\[\], BYTES)

```sql
event_decode(JSON, BYTES32[], BYTES)
```

Accepts a constant JSON event ABI object.

- Kind: table
- Execution context: Offline
- Behavior: Typed Event Decode
- Execution modes: Offline
- Input shape: Scalar Or Relation
- Planning contract: Bind Time Schema
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Table
- Schema stability: Abi Dependent
- Stability: Stable
- Side effects: None documented

### Requirements

- constant_event_abi

### Inputs

- `event_abi` (JSON; required; positional) — Constant JSON event ABI object; it defines the returned SQL columns and types.
- `topics` (BYTES32[]; required; positional) — LIST of BYTES32 values. For non-anonymous events, the first list element is EVM topic0; anonymous events begin with the first indexed argument.
- `data` (BYTES; required; positional) — ABI-encoded non-indexed event data.

### Result columns

ABI-derived event columns

Returns one row with a typed column per event parameter. Unnamed parameters use arg0, arg1, and so on; duplicate names receive numeric suffixes.

- `<event_parameters>` (ANY) — Dynamic placeholder for ABI-derived event columns.

### Dynamic columns

- Source: event_abi
- Names: Event parameter names
- Types: Mapped from ABI event parameter types
- Description: The constant event ABI determines the exact output names and SQL types during planning.

ABI-derived event columns. Returns one row with a typed column per event parameter. Unnamed parameters use arg0, arg1, and so on; duplicate names receive numeric suffixes.

### Examples

_Local SQL · Local_

```sql
WITH usdc_transfer AS (
  SELECT
    [
      event_signature('Transfer(address,address,uint256)'),
      evm_abi_word('0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472'::ADDRESS),
      evm_abi_word('0xa1db2fc9b2ceaf3cdf41fd11ffcb38404eae3906'::ADDRESS)
    ] AS topics,
    evm_abi_word(615568393::UINT256)::BYTES AS data
)
SELECT decoded.sender, decoded.recipient, decoded.value
FROM usdc_transfer
CROSS JOIN LATERAL event_decode(
  '{"type":"event","name":"Transfer","inputs":[{"indexed":true,"name":"sender","type":"address"},{"indexed":true,"name":"recipient","type":"address"},{"indexed":false,"name":"value","type":"uint256"}]}'::JSON,
  usdc_transfer.topics,
  usdc_transfer.data
) AS decoded;
-- 0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472 | 0xa1db2fc9b2ceaf3cdf41fd11ffcb38404eae3906 | 615568393
```

## Overload 2: event_decode(VARCHAR, BYTES32\[\], BYTES)

```sql
event_decode(VARCHAR, BYTES32[], BYTES)
```

Accepts a constant human-readable Solidity event declaration.

- Kind: table
- Execution context: Offline
- Behavior: Typed Event Decode
- Execution modes: Offline
- Input shape: Scalar Or Relation
- Planning contract: Bind Time Schema
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Table
- Schema stability: Abi Dependent
- Stability: Stable
- Side effects: None documented

### Requirements

- constant_event_abi

### Inputs

- `event_abi` (VARCHAR; required; positional) — Constant Solidity event declaration; it defines the returned SQL columns and types.
- `topics` (BYTES32[]; required; positional) — LIST of BYTES32 values. For non-anonymous events, the first list element is EVM topic0; anonymous events begin with the first indexed argument.
- `data` (BYTES; required; positional) — ABI-encoded non-indexed event data.

### Result columns

ABI-derived event columns

Returns one row with a typed column per event parameter. Unnamed parameters use arg0, arg1, and so on; duplicate names receive numeric suffixes.

- `<event_parameters>` (ANY) — Dynamic placeholder for ABI-derived event columns.

### Dynamic columns

- Source: event_abi
- Names: Event parameter names
- Types: Mapped from ABI event parameter types
- Description: The constant event ABI determines the exact output names and SQL types during planning.

ABI-derived event columns. Returns one row with a typed column per event parameter. Unnamed parameters use arg0, arg1, and so on; duplicate names receive numeric suffixes.

### Examples

_Local SQL · Local_

```sql
WITH usdc_transfer AS (
  SELECT
    [
      event_signature('Transfer(address,address,uint256)'),
      evm_abi_word('0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472'::ADDRESS),
      evm_abi_word('0xa1db2fc9b2ceaf3cdf41fd11ffcb38404eae3906'::ADDRESS)
    ] AS topics,
    evm_abi_word(615568393::UINT256)::BYTES AS data
)
SELECT decoded.sender, decoded.recipient, decoded.value
FROM usdc_transfer
CROSS JOIN LATERAL event_decode(
  'event Transfer(address indexed sender, address indexed recipient, uint256 value)'::VARCHAR,
  usdc_transfer.topics,
  usdc_transfer.data
) AS decoded;
-- 0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472 | 0xa1db2fc9b2ceaf3cdf41fd11ffcb38404eae3906 | 615568393
```

## Guidance

### Choose an event decoder

Use event_decode for typed table output when the event ABI is constant while the query is planned.

Use event_decode_json for compact JSON from already-materialized topics and data. Use log_decode_json when unknown, ambiguous, and decode-error statuses must remain visible.

Use evm_decode_log_for when ABI selection depends on a registered chain, address, and block range.

- Both scalar arguments and a single relation input are accepted. The constant event ABI determines the bind-time output schema.
- The canonical sample reconstructs USDC transaction 0x5cbf...3dde, log index 97, at Ethereum block 20,000,000 without an RPC call.
- Non-anonymous topics begin with topic0; anonymous topics begin with the first indexed parameter.
- Indexed dynamic values are returned as BYTES32 hashes. A mismatched non-anonymous topic0 is currently not rejected.
- Malformed topics or data raise an error.

## Related functions

- [event_decode_json](/docs/functions/event_decode_json.md) — Alternative
- [log_decode_json](/docs/functions/log_decode_json.md) — Alternative
- [evm_decode_log_for](/docs/functions/evm_decode_log_for.md) — Alternative
- [get_logs](/docs/functions/get_logs.md) — Usually After
