event_decode_json

Returns decoded EVM event arguments as compact JSON; use it for already-materialized topics and data when malformed input should produce NULL.

Example

Local

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

API reference

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

event_decode_json(JSON, BYTES32[], BLOB) #

Accepts a JSON ABI event fragment.

Inputs

Name Type Use
event_abi JSON

Single event ABI object with indexed flags and input types.

required positional
topics BYTES32[]

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

required positional
data BLOB

ABI-encoded non-indexed event data as BLOB.

required positional

Returns

Name Type
decoded_event JSON

Decoded event JSON. Returns values keyed by ABI input name. Unnamed inputs use arg_0, arg_1, and so on; booleans and lists remain JSON, EVM BLOB-backed values are 0x strings, and other scalars are strings.

Guidance

Decode logs offline

Use event_decode_json when topics and data are already available from get_logs, get_transaction_logs, or a fixture. The ABI event fragment controls how indexed topics and data words are decoded.

  • For a non-anonymous event, the first topic should be event_signature('EventName(types...)'). Anonymous events omit topic0 and begin with their first indexed parameter.
  • The canonical sample reconstructs USDC transaction 0x5cbf...3dde, log index 97, at Ethereum block 20,000,000 without an RPC call.
  • Indexed addresses are stored as left-padded BYTES32 topics.
  • Indexed dynamic values are represented by their indexed topic hash.
  • Non-indexed values are decoded from the data BLOB. A mismatched non-anonymous topic0 is currently not rejected.
  • Malformed ABI, topics, or data return NULL instead of raising a decode error.

Additional overloads

event_decode_json(VARCHAR, BYTES32[], BLOB) #

Accepts a JSON ABI event fragment as VARCHAR.

Inputs

Name Type Use
event_abi VARCHAR

Single JSON ABI event object supplied explicitly as VARCHAR.

required positional
topics BYTES32[]

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

required positional
data BLOB

ABI-encoded non-indexed event data as BLOB.

required positional

Returns

Name Type
decoded_event JSON

Decoded event JSON. Returns values keyed by ABI input name. Unnamed inputs use arg_0, arg_1, and so on; booleans and lists remain JSON, EVM BLOB-backed values are 0x strings, and other scalars are strings.

Overload examples

Local SQL

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

Related functions

Category and tags

Tag
ABI
Tag
Logs
Tag
RPC