getBlockHeight
Overview
The getBlockHeight JSON-RPC method is a fundamental and highly efficient query used to retrieve the current block height (also referred to as the slot number) of the Solana blockchain cluster. This method provides a lightweight mechanism to ascertain the latest progression point of the network without incurring the overhead of fetching full block data or blockhashes. It directly returns the highest slot number that the queried RPC node has observed and processed within its internal state.
Developers and operators leverage getBlockHeight primarily for monitoring the real-time liveness and synchronization status of the Solana network or a specific RPC node. It serves as a crucial health check, allowing quick verification that a node is actively processing blocks and keeping pace with the cluster's progression. Applications requiring a simple, up-to-date block identifier for display purposes, internal state management, or as a lightweight heartbeat signal can utilize this method effectively, reducing network latency and resource consumption compared to more data-intensive calls.
While other methods like getLatestBlockhash also provide information about the latest block, getBlockHeight is specifically optimized for scenarios where only the block number is required. Its simplicity and minimal response payload make it an ideal candidate for frequent polling or inclusion in performance-sensitive monitoring systems, enabling rapid assessment of the Solana network's current state and ensuring that services are operating against the most recent chain information.
Parameters
This method does not require any parameters.
Expected Response
The getBlockHeight method returns a single JSON number, which represents the current block height (slot) of the Solana blockchain as perceived by the RPC node.
1123456789| Property | Type | Description |
|---|---|---|
| (root) | Number | An unsigned 64-bit integer representing the highest slot number that the RPC node has finalized or processed. This value is continuously incrementing as new blocks are added to the Solana blockchain, reflecting the current progress and tip of the chain. It provides a simple, direct measure of the cluster's latest state. |
Usage Examples
TypeScript (Fetch)
1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2 method: "POST",
3 headers: {
4 "Content-Type": "application/json",
5 },
6 body: JSON.stringify({
7 jsonrpc: "2.0",
8 id: 1,
9 method: "getBlockHeight",
10 params: [] // Add relevant parameters here
11 }),
12});
13
14const data = await response.json();
15console.log(data);Python (Requests)
1import requests
2import json
3
4url = "http://[IP_ADDRESS]:[PORT]"
5payload = json.dumps({
6 "jsonrpc": "2.0",
7 "id": 1,
8 "method": "getBlockHeight",
9 "params": [] # Add relevant parameters here
10})
11headers = {
12 'Content-Type': 'application/json'
13}
14
15response = requests.request("POST", url, headers=headers, data=payload)
16print(response.text)Rust (reqwest)
1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = Client::new();
7 let res = client.post("http://[IP_ADDRESS]:[PORT]")
8 .json(&json!({
9 "jsonrpc": "2.0",
10 "id": 1,
11 "method": "getBlockHeight",
12 "params": [] // Add relevant parameters here
13 }))
14 .send()
15 .await?
16 .text()
17 .await?;
18
19 println!("{}", res);
20 Ok(())
21}