block_range

Resolves a UTC day or a pair of instants to a half-open block window [from_block, to_block). Each end is resolved independently with at_or_after: from_block is the first block at or after the start, and to_block is the first block at or after the end, so to_block itself lies outside the window. A DATE supplies UTC midnight at the start of that day and UTC midnight at the start of the next day. An end after the current tip timestamp resolves to tip + 1, so a window that has not ended yet holds every block mined so far.

Scalar functionLive RPC RPC

Example

Live RPC

-- Resolve the [from_block, to_block) bounds for one UTC day
SELECT
  (range).from_block AS from_block,
  (range).to_block AS to_block
FROM (
  SELECT block_range($client, '2024-01-15'::DATE) AS range
);

API reference

block_range(CLIENT, DATE) # RPC required

Accepts a DATE and returns the block interval covering that UTC calendar day.

Inputs

Name Type Use
client CLIENT

Attached live CLIENT for the chain to search.

required positional
date DATE

UTC calendar date. The range begins at midnight and ends at midnight at the start of the next day.

required positional

Returns

Name Type
block_range STRUCT(from_block BIGINT, to_block BIGINT)

Half-open block window. Returns STRUCT(from_block BIGINT, to_block BIGINT): from_block is the first block in the window and to_block the first block after it. Pass from_block and to_block - 1 to get_logs, whose bounds are both inclusive. Passing to_block unchanged also reads the first block after the window.

block_range(CLIENT, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE) # RPC required

Accepts two TIMESTAMPTZ values and resolves their absolute instants to a half-open block interval.

Inputs

Name Type Use
client CLIENT

Attached live CLIENT for the chain to search.

required positional
from_timestamp TIMESTAMP WITH TIME ZONE

Absolute TIMESTAMPTZ start instant resolved with at_or_after.

required positional
to_timestamp TIMESTAMP WITH TIME ZONE

Absolute TIMESTAMPTZ end instant resolved with at_or_after. It need not follow the start.

required positional

Returns

Name Type
block_range STRUCT(from_block BIGINT, to_block BIGINT)

Half-open block window. Returns STRUCT(from_block BIGINT, to_block BIGINT): from_block is the first block in the window and to_block the first block after it. Pass from_block and to_block - 1 to get_logs, whose bounds are both inclusive. Passing to_block unchanged also reads the first block after the window.

block_range(CLIENT, TIMESTAMP, TIMESTAMP) # RPC required

Accepts two plain TIMESTAMP values, interprets them as UTC, and returns a half-open block interval.

Inputs

Name Type Use
client CLIENT

Attached live CLIENT for the chain to search.

required positional
from_timestamp TIMESTAMP

UTC TIMESTAMP start instant resolved with at_or_after.

required positional
to_timestamp TIMESTAMP

UTC TIMESTAMP end instant resolved with at_or_after. It need not follow the start.

required positional

Returns

Name Type
block_range STRUCT(from_block BIGINT, to_block BIGINT)

Half-open block window. Returns STRUCT(from_block BIGINT, to_block BIGINT): from_block is the first block in the window and to_block the first block after it. Pass from_block and to_block - 1 to get_logs, whose bounds are both inclusive. Passing to_block unchanged also reads the first block after the window.

Guidance

Failures and ordering

NULL input, transport initialization failure, or boundary-search failure returns NULL. A search failure affects every row sharing that transport in the input vector.

A malformed, detached, or non-live CLIENT raises an error.

Historical boundaries require a provider that retains the requested blocks.

Start and end boundaries are resolved independently; reversed inputs are not rejected.