latest_block

Returns the latest block number reported by the RPC provider. Because the chain head moves, persist the result before using it as a reproducible boundary.

Example

Needs RPC · RPC required

1
-- Get current block number
2
SELECT latest_block($client) AS head_block;
Notebook ready in readonly mode.

API reference

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

latest_block(CLIENT) # RPC required

Reads the provider's latest mined block number through the supplied client.

Inputs

Name Type Use
client CLIENT

Attached live CLIENT for the chain whose head should be read.

required positional

Returns

Name Type
block_number BIGINT

Latest block number. Returns the provider's current chain head as a BIGINT. This is intentionally time-varying; persist the returned number before using it as historical evidence.

Examples

Named parameters · RPC required

1
-- Compare the moving head with the provider's finalized checkpoint
2
WITH head AS (
3
SELECT latest_block($client) AS head_block
4
), finalized AS (
5
SELECT number AS finalized_block
6
FROM get_block($client, 'finalized')
7
)
8
SELECT head_block, finalized_block, head_block - finalized_block AS finality_gap_blocks
9
FROM head, finalized;
Notebook ready in readonly mode.

Related functions

Category and tags

Category
Chain reads
Tag
RPC