Loading

block_range

Scalar function

Get the block range for a specific date or time period. Perfect for querying all events (transfers, swaps, mints) that happened on a particular day or within a date range on Ethereum, Base, or other EVM chains.

block_range(TRANSPORT, DATE)

Pass a DATE to get all blocks for that entire day (midnight to midnight UTC). Returns from_block (inclusive) and to_block (exclusive) - use directly with get_logs to fetch all events for that day.

Parameters

Name Type
transport TRANSPORT
date DATE

Returns

Name Type
block_range STRUCT(from_block BIGINT, to_block BIGINT)
1
-- Get all USDC transfers on January 15th, 2024
2
WITH r AS (SELECT block_range($transport, '2024-01-15'::DATE))
3
SELECT * FROM get_logs($transport,
4
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
5
'Transfer(address,address,uint256)',
6
(r).from_block, (r).to_block);
Notebook ready in readonly mode.

block_range(TRANSPORT, TIMESTAMP WITH TIME ZONE, TIMESTAMP WITH TIME ZONE)

Pass two timestamps to get blocks for a custom time range. Use for 'last 7 days', 'last hour', or any arbitrary time window. Returns from_block (inclusive) and to_block (exclusive).

Parameters

Name Type
transport TRANSPORT
from_timestamp TIMESTAMP WITH TIME ZONE
to_timestamp TIMESTAMP WITH TIME ZONE

Returns

Name Type
block_range STRUCT(from_block BIGINT, to_block BIGINT)
1
-- Get block range for the last 7 days
2
SELECT block_range($transport, now() - INTERVAL '7 days', now());
3
 
4
-- Get block range for a specific hour
5
SELECT block_range($transport,
6
'2024-06-15 14:00:00+00'::TIMESTAMPTZ,
7
'2024-06-15 15:00:00+00'::TIMESTAMPTZ);
Notebook ready in readonly mode.

block_range(TRANSPORT, TIMESTAMP, TIMESTAMP)

Parameters

Name Type
arg1 TRANSPORT
arg2 TIMESTAMP
arg3 TIMESTAMP

Returns

Name Type
result STRUCT(from_block BIGINT, to_block BIGINT)