View this page as Markdown

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.

Example

Local

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

API reference

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

event_decode(JSON, BYTES32[], BYTES) #

Accepts a constant JSON event ABI object.

Note: The event ABI must be constant at planning time.

Inputs

Name Type Use
event_abi JSON

Constant JSON event ABI object; it defines the returned SQL columns and 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 BYTES

ABI-encoded non-indexed event data.

required positional

Result columns

Name Type
<event_parameters> ANY

Dynamic placeholder for ABI-derived event columns.

...

ABI-derived event columns

The constant event ABI determines the exact output names and SQL types during planning.

Columns
No fixed columns
Source
event_abi
Names
Event parameter names
Types
Mapped from ABI event parameter types

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.

Additional overloads

event_decode(VARCHAR, BYTES32[], BYTES) #

Accepts a constant human-readable Solidity event declaration.

Note: The event ABI must be constant at planning time.

Inputs

Name Type Use
event_abi VARCHAR

Constant Solidity event declaration; it defines the returned SQL columns and 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 BYTES

ABI-encoded non-indexed event data.

required positional

Result columns

Name Type
<event_parameters> ANY

Dynamic placeholder for ABI-derived event columns.

...

ABI-derived event columns

The constant event ABI determines the exact output names and SQL types during planning.

Columns
No fixed columns
Source
event_abi
Names
Event parameter names
Types
Mapped from ABI event parameter types

Overload examples

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

Related functions

Category and tags

Tag
ABI
Tag
Logs
Tag
Typed
Tag
RPC