get_logs

Returns EVM event logs matching the supplied emitter, block, and topic filters. Supply a human-readable event signature or JSON ABI to append typed decoded fields.

Example

Needs RPC · RPC required

1
-- Recent finalized-window USDC Transfer aggregation
2
WITH head AS (
3
SELECT number AS head_block
4
FROM get_block($client, 'finalized')
5
),
6
transfers AS (
7
SELECT
8
"to",
9
value
10
FROM head,
11
get_logs(
12
$client,
13
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::ADDRESS, -- Ethereum mainnet USDC
14
'event Transfer(address indexed from, address indexed to, uint256 value)',
15
head_block - 5,
16
head_block
17
)
18
)
19
SELECT
20
"to",
21
sum(value) AS raw_value,
22
format_units(sum(value), 6) AS usdc_value
23
FROM transfers
24
GROUP BY "to"
25
ORDER BY raw_value DESC;
Notebook ready in readonly mode.

API reference

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

get_logs(CLIENT, ADDRESS, VARCHAR) # RPC required

Decodes a human-readable event signature for one emitter without explicit block bounds.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressADDRESS

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_signatureVARCHAR

Event declaration used to decode matching logs.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
topic3BYTES32 or BYTES32[]

Exact value or OR-list for the third indexed parameter.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer

Guidance

Choose a stable block window

from_block and to_block are both inclusive. block_range returns an exclusive to_block, so subtract one from its upper bound.

Use bounded finalized ranges for repeatable reads. Historical windows require a provider that retains the requested blocks.

No-range overloads are intended for limited discovery; provider range limits can reject or truncate broad queries.

SQL LIMIT trims rows after fetching; reduce RPC work with emitter, topic, and block filters.

Named parameters · RPC required

1
-- Recent finalized-window WETH Transfer decoding with a JSON ABI
2
WITH head AS (
3
SELECT number::BIGINT AS head_block
4
FROM get_block($client, 'finalized')
5
)
6
SELECT transaction_hash, log_index, "from", "to", format_units(value, 18) AS weth_amount
7
FROM head,
8
get_logs(
9
$client,
10
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::ADDRESS,
11
'{"type":"event","name":"Transfer","inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}]}'::JSON,
12
head_block - 5,
13
head_block
14
);
Notebook ready in readonly mode.

Filter emitters and indexed parameters

Pass one ADDRESS, an ADDRESS[] list, or NULL::ADDRESS when the provider supports addressless log queries.

Each topic position accepts one BYTES32 value or a BYTES32[] OR-list.

  • For non-anonymous events, topic0 is the event selector.
  • topic1, topic2, and topic3 correspond to the first three indexed event parameters.
  • For Transfer(address indexed from, address indexed to, uint256 value), topic1 is from and topic2 is to.
  • Use event_signature to build topic0 and evm_abi_word to encode an indexed address.

Compare token activity

Use an ADDRESS[] overload when the same event should be compared across a small set of contracts.

Keep the window bounded and use a finalized checkpoint for a stable recent read.

  • USDC and USDT both use 6 decimals.
  • Group by the emitting address to keep results attributable to each token contract.

Named parameters · RPC required

1
WITH head AS (
2
SELECT number AS head_block
3
FROM get_block($client, 'finalized')
4
),
5
transfers AS (
6
SELECT
7
address,
8
value
9
FROM head,
10
get_logs(
11
$client,
12
[
13
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
14
'0xdAC17F958D2ee523a2206206994597C13D831ec7'
15
]::ADDRESS[],
16
'event Transfer(address indexed from, address indexed to, uint256 value)',
17
head_block - 5,
18
head_block
19
)
20
)
21
SELECT
22
address AS token,
23
count(*) AS transfer_count,
24
sum(value) AS raw_value,
25
format_units(sum(value), 6) AS token_value
26
FROM transfers
27
GROUP BY address
28
ORDER BY address;
Notebook ready in readonly mode.

Topic filters

For ERC-20 Transfer(address indexed from, address indexed to, uint256 value), topic0 is the event selector, topic1 is from, and topic2 is to.

Addressless scans require a provider that supports unaddressed eth_getLogs requests.

  • Build topic0 with event_signature instead of copying a hash.
  • Build indexed address topics with evm_abi_word instead of manually padding addresses.
  • Use BYTES32[] for an OR filter.

Additional overloads

get_logs(CLIENT, ADDRESS, JSON) # RPC required

Decodes a JSON event ABI for one emitter without explicit block bounds.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressADDRESS

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_abiJSON

JSON event fragment used to filter and decode matching logs.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
topic3BYTES32 or BYTES32[]

Exact value or OR-list for the third indexed parameter.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS, VARCHAR, BIGINT) # RPC required

Decodes a human-readable event signature for one emitter from an inclusive starting block.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressADDRESS

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_signatureVARCHAR

Event declaration used to decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS, JSON, BIGINT) # RPC required

Decodes a JSON event ABI for one emitter from an inclusive starting block.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressADDRESS

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_abiJSON

JSON event fragment used to filter and decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS, VARCHAR, BIGINT, BIGINT) # RPC required

Decodes a human-readable event signature for one emitter between inclusive block bounds.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressADDRESS

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_signatureVARCHAR

Event declaration used to decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
to_blockBIGINT

Inclusive last block.

requiredpositional
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS, JSON, BIGINT, BIGINT) # RPC required

Decodes a JSON event ABI for one emitter between inclusive block bounds.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressADDRESS

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_abiJSON

JSON event fragment used to filter and decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
to_blockBIGINT

Inclusive last block.

requiredpositional
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS[], VARCHAR) # RPC required

Decodes a human-readable event signature for multiple emitters without explicit block bounds. Addresses are batched in groups of at most 50.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressesADDRESS[]

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_signatureVARCHAR

Event declaration used to decode matching logs.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
topic3BYTES32 or BYTES32[]

Exact value or OR-list for the third indexed parameter.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS[], JSON) # RPC required

Decodes a JSON event ABI for multiple emitters without explicit block bounds.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressesADDRESS[]

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_abiJSON

JSON event fragment used to filter and decode matching logs.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
topic3BYTES32 or BYTES32[]

Exact value or OR-list for the third indexed parameter.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
Show 4 more overloads
get_logs(CLIENT, ADDRESS[], VARCHAR, BIGINT) # RPC required

Decodes a human-readable event signature for multiple emitters from an inclusive starting block.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressesADDRESS[]

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_signatureVARCHAR

Event declaration used to decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS[], JSON, BIGINT) # RPC required

Decodes a JSON event ABI for multiple emitters from an inclusive starting block.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressesADDRESS[]

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_abiJSON

JSON event fragment used to filter and decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
topic0BYTES32 or BYTES32[]

Exact value or OR-list; the event selector for non-anonymous events.

optionalnamed
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS[], VARCHAR, BIGINT, BIGINT) # RPC required

Decodes a human-readable event signature for multiple emitters between inclusive block bounds. Addresses are batched in groups of at most 50.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressesADDRESS[]

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_signatureVARCHAR

Event declaration used to decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
to_blockBIGINT

Inclusive last block.

requiredpositional
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer
get_logs(CLIENT, ADDRESS[], JSON, BIGINT, BIGINT) # RPC required

Decodes a JSON event ABI for multiple emitters between inclusive block bounds.

Inputs

NameTypeUse
clientCLIENT

Live, pinned, or retained EVM state.

requiredpositional
addressesADDRESS[]

ADDRESS, NULL::ADDRESS, or ADDRESS[] emitter filter.

requiredpositional
event_abiJSON

JSON event fragment used to filter and decode matching logs.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
to_blockBIGINT

Inclusive last block.

requiredpositional
Showing fewer

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

transaction_hashBYTES32

Emitting transaction hash.

transaction_indexINTEGER

Transaction position in the block.

Showing fewer

Related functions

Category and tags

Category
Chain reads
Tag
RPC