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
{"id":"sample_2oq8vr","title":"Sample","code":"-- Get current block number\nSELECT 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) #
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
{"id":"sample_hrchxq","title":"Sample","code":"-- Compare the moving head with the provider's finalized checkpoint\nWITH head AS (\n SELECT latest_block($client) AS head_block\n), finalized AS (\n SELECT number AS finalized_block\n FROM get_block($client, 'finalized')\n)\nSELECT head_block, finalized_block, head_block - finalized_block AS finality_gap_blocks\nFROM head, finalized;"}
Notebook ready in readonly mode.
Related functions
Category and tags
- Category
- Chain reads
- Tag
- RPC