log_decode_json

Returns a status-rich JSON description of one EVM log; use it when unknown, ambiguous, and malformed logs must remain distinguishable.

Example

Local

1
SELECT log_decode_json(
2
'[{"type":"event","name":"Transfer","inputs":[
3
{"name":"sender","type":"address","indexed":true},
4
{"name":"recipient","type":"address","indexed":true},
5
{"name":"value","type":"uint256","indexed":false}
6
]}]'::JSON,
7
[
8
event_signature('Transfer(address,address,uint256)'),
9
evm_abi_word('0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472'::ADDRESS),
10
evm_abi_word('0xa1db2fc9b2ceaf3cdf41fd11ffcb38404eae3906'::ADDRESS)
11
],
12
evm_abi_word(615568393::UINT256)::BYTES
13
) AS diagnostic;
14
-- diagnostic.decode_status = decoded
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

log_decode_json(JSON, BYTES32[], BYTES) #

Decodes topics and data using an event ABI supplied as JSON.

Inputs

Name Type Use
abi JSON

Event ABI JSON containing the event definition.

required positional
topics BYTES32[]

Event topics as BYTES32 values. For non-anonymous events, the first list element is EVM topic0; anonymous events begin with the first indexed argument.

required positional
data BYTES

Raw event data bytes.

required positional

Returns

Name Type
diagnostic JSON

Log diagnostic JSON. Fields by decode_status: decoded has signature, name, and args (signature currently contains the event name for compatibility; registry decoding may add abi_label); unknown has topic0, topics, data, and data_words; ambiguous has topic0; decode_error has topic0 or error.

Guidance

Decode event rows

Use log_decode_json after fetching logs when one JSON value must preserve whether decoding succeeded, found no matching ABI, found multiple candidates, or failed. Required NULL inputs propagate NULL.

  • Use table-shaped log functions when you need to join decoded event fields across many rows.
  • Use event_decode_json when NULL on malformed input is preferable to diagnostic statuses.
  • The canonical sample reconstructs USDC transaction 0x5cbf...3dde, log index 97, at Ethereum block 20,000,000 without an RPC call.
  • Non-anonymous logs begin with topic0; anonymous logs begin with their first indexed parameter.
  • Indexed dynamic parameters remain BYTES32 hashes. Unnamed inputs use arg0, arg1, and so on.
  • Keep topic and data bytes alongside decoded JSON for review and troubleshooting.

Additional overloads

log_decode_json(VARCHAR, BYTES32[], BYTES) #

Decodes topics and data using an event ABI supplied as VARCHAR.

Inputs

Name Type Use
abi VARCHAR

Event ABI JSON containing the event definition.

required positional
topics BYTES32[]

Event topics as BYTES32 values. For non-anonymous events, the first list element is EVM topic0; anonymous events begin with the first indexed argument.

required positional
data BYTES

Raw event data bytes.

required positional

Returns

Name Type
diagnostic JSON

Log diagnostic JSON. Fields by decode_status: decoded has signature, name, and args (signature currently contains the event name for compatibility; registry decoding may add abi_label); unknown has topic0, topics, data, and data_words; ambiguous has topic0; decode_error has topic0 or error.

Overload examples

Local SQL

1
SELECT log_decode_json(
2
'[{"type":"event","name":"Transfer","inputs":[
3
{"name":"sender","type":"address","indexed":true},
4
{"name":"recipient","type":"address","indexed":true},
5
{"name":"value","type":"uint256","indexed":false}
6
]}]'::VARCHAR,
7
[
8
event_signature('Transfer(address,address,uint256)'),
9
evm_abi_word('0xcb83ca9633ad057bd88a48a5b6e8108d97ad4472'::ADDRESS),
10
evm_abi_word('0xa1db2fc9b2ceaf3cdf41fd11ffcb38404eae3906'::ADDRESS)
11
],
12
evm_abi_word(615568393::UINT256)::BYTES
13
) AS diagnostic;
14
-- diagnostic.decode_status = decoded

Related functions

Category and tags

Tag
ABI
Tag
Events