# evm_decode_log_for

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

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

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

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

## Overload 1: evm_decode_log_for(UBIGINT, ADDRESS, UBIGINT, BYTES32\[\], BYTES)

```sql
evm_decode_log_for(UBIGINT, ADDRESS, UBIGINT, BYTES32[], BYTES)
```

Looks up ABI metadata for the emitting contract context, then decodes the log.

- Kind: scalar
- Execution context: Offline
- Behavior: Registry Backed Log 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) — Log-emitting contract address.
- `block_number` (UBIGINT; required; positional) — Block number for ABI registry validity range selection.
- `topics` (BYTES32[]; required; positional) — Event topics as BYTES32 values, including topic0.
- `data` (BYTES; required; positional) — Raw event data bytes.

### Returns

Contextual log diagnostic JSON

Uses log_decode_json shapes; decoded results add abi_label when the registration has a label.

- `diagnostic` (JSON)

Contextual log diagnostic JSON. Uses log_decode_json shapes; decoded results add abi_label when the registration has a label.

### Examples

_Local SQL · Local_

```sql
WITH registered AS MATERIALIZED (
  SELECT evm_register_contract_abi(
    1,
    '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::ADDRESS,
    '[{"type":"event","name":"Transfer","inputs":[{"name":"sender","type":"address","indexed":true},{"name":"recipient","type":"address","indexed":true},{"name":"value","type":"uint256","indexed":false}]}]'::JSON,
    'USDC at block 20,000,000',
    20000000,
    20000000
  ) AS ok
)
SELECT evm_decode_log_for(
  1,
  '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::ADDRESS,
  20000000,
  [
    event_signature('Transfer(address,address,uint256)'),
    evm_abi_word('0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472'::ADDRESS),
    evm_abi_word('0xa1db2fc9b2ceaf3cdf41fd11ffcb38404eae3906'::ADDRESS)
  ],
  evm_abi_word(615568393::UINT256)::BYTES
) AS diagnostic
FROM registered
WHERE ok;
-- diagnostic.name = Transfer
```

## 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 emitter ABI before decoding. Required NULL inputs propagate NULL.
- If no registration matches, the result is unknown and retains topic0, every topic, data, and padded data_words.

## Related functions

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