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.

Scalar functionLive RPC RPC

Example

Live RPC

-- Get current block number
SELECT latest_block($client) AS head_block;

API reference

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

Live RPC

-- Compare the moving head with the provider's finalized checkpoint
WITH head AS (
  SELECT latest_block($client) AS head_block
), finalized AS (
  SELECT number AS finalized_block
  FROM get_block($client, 'finalized')
)
SELECT head_block, finalized_block, head_block - finalized_block AS finality_gap_blocks
FROM head, finalized;