get_logs

Reads logs matching emitter, inclusive block bounds, and topic filters. Live clients use eth_getLogs; retained execution clients read stored execution logs.

Table functionLive RPC RPC

Example

Live RPC

-- Recent finalized-window USDC Transfer aggregation
WITH head AS (
  SELECT number AS head_block
  FROM get_block($client, 'finalized')
),
transfers AS (
  SELECT
    l."to",
    l.value
  FROM head
  JOIN get_logs(
    $client,
    '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::ADDRESS, -- Ethereum mainnet USDC
    'event Transfer(address indexed from, address indexed to, uint256 value)'
  ) AS l ON l.block_number BETWEEN head_block - 5 AND head_block
)
SELECT
  "to",
  sum(value) AS raw_value,
  format_units(sum(value), 6) AS usdc_value
FROM transfers
GROUP BY "to"
ORDER BY raw_value DESC;

API reference

get_logs(CLIENT, ADDRESS | ADDRESS[], VARCHAR | JSON) # RPC required

Read logs filtered by the query. A live CLIENT takes its bounds from WHERE or a join, block_number BETWEEN a AND b with constants or a joined relation's columns, and raises before any request without both; = , IN and OR on address and indexed fields go to the node, a log matching two branches once; values from a joined relation are read once and sent as lists. A retained execution CLIENT reads its stored logs; a pinned one needs from_block and to_block. A failed RPC request raises.

Exact signatures (4)
  • get_logs(CLIENT, ADDRESS, VARCHAR)
  • get_logs(CLIENT, ADDRESS, JSON)
  • get_logs(CLIENT, ADDRESS[], VARCHAR)
  • get_logs(CLIENT, ADDRESS[], JSON)

Inputs

NameTypeUse
clientCLIENT

Attached live CLIENT for RPC logs, bounded by from_block and to_block or by a WHERE on block_number; attached pinned CLIENT with both block bounds; or retained execution CLIENT without block bounds. Retained execution reads do not require an attached TRANSPORT; detached pinned clients are rejected.

requiredpositional
addressADDRESS | ADDRESS[]

ADDRESS, NULL::ADDRESS for no emitter filter, or ADDRESS[]. A NULL or empty ADDRESS[] reads no logs. RPC address lists are de-duplicated and split into requests of at most 50 addresses.

requiredpositional
event_signature / event_abiVARCHAR | JSON

VARCHAR: Event declaration used for topic0 filtering and decoding. It must be foldable to add decoded output columns. JSON: JSON event fragment used for topic0 filtering and decoding. It must be foldable to add decoded output columns.

requiredpositional
topic0BYTES32 or list

Exact value or OR-list at topic position 0. For RPC requests it replaces the event-derived selector; only logs of the declared event decode, and retained execution logs must also match the event selector.

optionalnamed
topic1BYTES32 or list

Exact value or OR-list for the first indexed parameter; a constant or a column read per row. A WHERE on the decoded field does the same.

optionalnamed

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

block_timestampTIMESTAMP

Containing block time in UTC, from the provider's log, or the block header when the log lacks it.

transaction_hashBYTES32

Emitting transaction hash.

get_logs(CLIENT, ADDRESS | ADDRESS[], VARCHAR | JSON, BIGINT) # RPC required

Read logs from an inclusive lower bound to the statement's latest block, the one every read of the statement sees; the host refuses it on a live CLIENT, pinned clients require both bounds and retained states reject bounds. A failed RPC request raises.

Exact signatures (4)
  • get_logs(CLIENT, ADDRESS, VARCHAR, BIGINT)
  • get_logs(CLIENT, ADDRESS, JSON, BIGINT)
  • get_logs(CLIENT, ADDRESS[], VARCHAR, BIGINT)
  • get_logs(CLIENT, ADDRESS[], JSON, BIGINT)

Inputs

NameTypeUse
clientCLIENT

Attached live CLIENT for RPC logs, bounded by from_block and to_block or by a WHERE on block_number; attached pinned CLIENT with both block bounds; or retained execution CLIENT without block bounds. Retained execution reads do not require an attached TRANSPORT; detached pinned clients are rejected.

requiredpositional
addressADDRESS | ADDRESS[]

ADDRESS, NULL::ADDRESS for no emitter filter, or ADDRESS[]. A NULL or empty ADDRESS[] reads no logs. RPC address lists are de-duplicated and split into requests of at most 50 addresses.

requiredpositional
event_signature / event_abiVARCHAR | JSON

VARCHAR: Event declaration used for topic0 filtering and decoding. It must be foldable to add decoded output columns. JSON: JSON event fragment used for topic0 filtering and decoding. It must be foldable to add decoded output columns.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
topic0BYTES32 or list

Exact value or OR-list at topic position 0. For RPC requests it replaces the event-derived selector; only logs of the declared event decode, and retained execution logs must also match the event selector.

optionalnamed

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

block_timestampTIMESTAMP

Containing block time in UTC, from the provider's log, or the block header when the log lacks it.

transaction_hashBYTES32

Emitting transaction hash.

get_logs(CLIENT, ADDRESS | ADDRESS[], VARCHAR | JSON, BIGINT, BIGINT) # RPC required

Read an inclusive range using a live or attached pinned CLIENT. A NULL bound, or from_block after to_block, raises. Chunks start at 2000 blocks and double while sparse, up to max_block_range; retryable failures retry five times, then raise. first := n or last := n reads from that end and stops at the n-th log by (block_number, log_index); so does ORDER BY block_number, log_index [DESC] LIMIT n directly over the call. A statement makes at most determica_max_log_requests (200) eth_getLogs requests, checked from the bounds before the first; a range that needs more raises with its cost, never partial rows. Topics are BYTES32 or ADDRESS words or lists, constant or per row; NULL or empty raises. An empty ADDRESS[] reads nothing. Logs carry block_timestamp. A pinned CLIENT reads no block past its pin, and raises when its block is no longer canonical after the read. A removed log, a height read with two hashes, or a page under an hour old whose block changed after it was read raises STATE_SOURCE_INCONSISTENT. check_sql refuses a literal from_block below the deployment block a contract's card shows.

Exact signatures (4)
  • get_logs(CLIENT, ADDRESS, VARCHAR, BIGINT, BIGINT)
  • get_logs(CLIENT, ADDRESS, JSON, BIGINT, BIGINT)
  • get_logs(CLIENT, ADDRESS[], VARCHAR, BIGINT, BIGINT)
  • get_logs(CLIENT, ADDRESS[], JSON, BIGINT, BIGINT)

Inputs

NameTypeUse
clientCLIENT

Attached live CLIENT for RPC logs, bounded by from_block and to_block or by a WHERE on block_number; attached pinned CLIENT with both block bounds; or retained execution CLIENT without block bounds. Retained execution reads do not require an attached TRANSPORT; detached pinned clients are rejected.

requiredpositional
addressADDRESS | ADDRESS[]

ADDRESS, NULL::ADDRESS for no emitter filter, or ADDRESS[]. A NULL or empty ADDRESS[] reads no logs. RPC address lists are de-duplicated and split into requests of at most 50 addresses.

requiredpositional
event_signature / event_abiVARCHAR | JSON

VARCHAR: Event declaration used for topic0 filtering and decoding. It must be foldable to add decoded output columns. JSON: JSON event fragment used for topic0 filtering and decoding. It must be foldable to add decoded output columns.

requiredpositional
from_blockBIGINT

Inclusive first block.

requiredpositional
to_blockBIGINT

Inclusive last block.

requiredpositional

Result columns

NameType
addressADDRESS

Log emitter.

block_hashBYTES32

Containing block hash.

block_numberBLOCK_NUMBER

Containing block height.

block_timestampTIMESTAMP

Containing block time in UTC, from the provider's log, or the block header when the log lacks it.

transaction_hashBYTES32

Emitting transaction hash.

Guidance

Request construction

from_block and to_block are inclusive. With both bounds, get_logs reads the range in chunks: the first spans 2000 blocks (or the CLIENT's max_block_range when smaller), and a chunk with fewer than 5000 logs doubles the next, up to max_block_range. A provider's range limit fixes the chunk for the rest of the read. After a sparse chunk the next ten go as one JSON-RPC batch.

first := n or last := n keeps the n earliest or latest logs by (block_number, log_index), reading from that end up to the n-th; ORDER BY block_number[, log_index] LIMIT n directly over the call does too.

A statement makes at most determica_max_log_requests (200) eth_getLogs requests: a range that needs more raises before reading, a read that reaches it raises; never partial rows.

A NULL from_block or to_block raises; it never reads without bounds. from_block after to_block raises.

Without from_block, a live read takes its bounds from the query: block_number BETWEEN a AND b (or >= and <=, or =) in a WHERE or a join condition, with constants or columns of a joined relation, as in h JOIN get_logs(...) AS l ON l.block_number BETWEEN h.lo AND h.hi. A live read with no lower and upper bound raises before any request and says why the WHERE did not bound it.

block_timestamp comes with each log from the provider, so a log's time needs no header read; a log without it (or with 0x0) takes its block header's, one batched read per such block.

  • RPC ADDRESS[] values are split into requests of at most 50 addresses.
  • Pinned clients require both from_block and to_block. Retained execution clients reject either bound.

Failure handling

A request with both bounds retries retryable failures up to five times per chunk, then raises an error. A non-retryable provider failure raises immediately.

A request without both bounds that fails raises; an empty result always means no matching logs.

A log that is not the declared event keeps its row with NULL decoded columns: its topic0 differs, its topic count is not one plus the indexed inputs, or its data does not decode. ERC-20 and ERC-721 Transfer share topic0, and an ERC-721 Transfer carries its token id as a fourth topic.

Reproducible and efficient reads

Resolve and persist numeric bounds from a finalized head when later runs must scan the same block window.

A total at a block is a state read, not a sum of events. Emitter, topic and block filters reduce RPC work.

Live RPC

-- Recent finalized-window WETH Transfer decoding with a JSON ABI
WITH head AS (
  SELECT number::BIGINT AS head_block
  FROM get_block($client, 'finalized')
)
SELECT l.transaction_hash, l.log_index, l."from", l."to", format_units(l.value, 18) AS weth_amount
FROM head
JOIN get_logs(
  $client,
  '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::ADDRESS,
  '{"type":"event","name":"Transfer","inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}]}'::JSON
) AS l ON l.block_number BETWEEN head_block - 5 AND head_block;

Topic matching

Topic filters are ANDed by position. A BYTES32[] value is an OR-list within one position.

For RPC requests, an explicit topic0 replaces the selector derived from a non-anonymous event.

Retained execution logs are decoded only when they match both the event selector and every explicit topic filter, including topic0.

  • topic1, topic2, and topic3 correspond to the first three indexed event parameters.
  • A WHERE or join condition on the call's columns is sent to the node, and still applies, so only the read narrows: = or IN on an indexed field becomes its topic, = on address the emitter. An OR of equalities on fields at different positions ("from" = W OR "to" = W) is one request per position; a log both match comes back once. The value is a constant or a column of a joined relation (a wallet table, read_contract's result, another get_logs): that relation runs once and its distinct values go as one list, ADDRESS[] emitters split by 50.
  • Not sent: an OR across two calls or with an unindexed field, a filter above a LIMIT, aggregate or window over the logs, NOT IN and NOT EXISTS. The read is then as written.
  • A topic value is a BYTES32, or an ADDRESS padded as evm_abi_word pads it; encode other values with evm_abi_word. A NULL, an empty list or any other value raises. A topic from a column (LATERAL) is read per row.

Live RPC

WITH head AS (
  SELECT number AS head_block
  FROM get_block($client, 'finalized')
),
transfers AS (
  SELECT
    l.address,
    l.value
  FROM head
  JOIN get_logs($client, NULL::ADDRESS, 'event Transfer(address indexed from, address indexed to, uint256 value)') AS l
    ON l.block_number BETWEEN head_block - 5 AND head_block
  WHERE l.address IN (
    '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'::ADDRESS,
    '0xdAC17F958D2ee523a2206206994597C13D831ec7'::ADDRESS
  )
)
SELECT
  address AS token,
  count(*) AS transfer_count,
  sum(value) AS raw_value,
  format_units(sum(value), 6) AS token_value
FROM transfers
GROUP BY address
ORDER BY address;

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.