# 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.

Canonical HTML: <https://determica.com/docs/functions/latest_block>

- Kind: scalar function
- Category: [Chain reads](/docs/category/chain-reads.md)
- Tags: RPC

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.

## Overload 1: latest_block(CLIENT)

```sql
latest_block(CLIENT)
```

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

- Kind: scalar
- Execution context: Live RPC
- Behavior: Immediate Read
- Execution modes: Live Client
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: External State
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: network_io

### Requirements

- attached_live_client
- rpc

### Risks

- provider_limits
- chain_reorganization

### Inputs

- `client` (CLIENT; required; positional) — Attached live CLIENT for the chain whose head should be read.

### Returns

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.

- `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 · Needs RPC · RPC required_

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

_Named parameters · Needs RPC · RPC required_

```sql
-- 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;
```

## Related functions

- [get_logs](/docs/functions/get_logs.md) — Usually Before
- [get_block](/docs/functions/get_block.md) — Alternative
- [block_range](/docs/functions/block_range.md) — See Also
