getBlock
Returns the identity and transaction information for a confirmed block in the ledger. This method is essential for block explorers, indexers, and analytics services that need to inspect the complete contents of a specific slot. It returns transaction details, rewards, and block metadata including the blockhash, parent slot, and block time.
Parameters
| # | Type | Required | Description |
|---|---|---|---|
| 1 | u64 | Yes | Slot number of the block to retrieve, as a u64 integer |
| 2 | object | No | Configuration object |
Configuration object fields:
| Field | Type | Description |
|---|---|---|
commitment | string | Commitment level: processed, confirmed, or finalized (default finalized) |
encoding | string | Transaction encoding: json, jsonParsed, base58, or base64 (default json) |
transactionDetails | string | Detail level: full, accounts, signatures, or none (default full) |
maxSupportedTransactionVersion | number | Max transaction version to return. If omitted, only legacy transactions are returned |
rewards | bool | Whether to populate the rewards array (default true) |
Response
Returns null if the block is not available. Otherwise returns an object:
| Field | Type | Description |
|---|---|---|
blockhash | string | The blockhash of this block (base-58) |
previousBlockhash | string | The blockhash of the parent block |
parentSlot | u64 | The slot index of the parent block |
transactions | array | Array of transaction objects if transactionDetails is not none |
rewards | array | Array of reward objects if rewards is true |
blockTime | `i64 | null` |
blockHeight | `u64 | null` |
Code Examples
cURL
1curl http://[IP_ADDRESS]:[PORT] -X POST -H "Content-Type: application/json" -d '{
2 "jsonrpc": "2.0",
3 "id": 1,
4 "method": "getBlock",
5 "params": [
6 166974442,
7 {
8 "encoding": "jsonParsed",
9 "maxSupportedTransactionVersion": 0,
10 "transactionDetails": "full",
11 "rewards": false
12 }
13 ]
14}'TypeScript
1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2 method: "POST",
3 headers: { "Content-Type": "application/json" },
4 body: JSON.stringify({
5 jsonrpc: "2.0",
6 id: 1,
7 method: "getBlock",
8 params: [
9 166974442,
10 {
11 encoding: "jsonParsed",
12 maxSupportedTransactionVersion: 0,
13 transactionDetails: "full",
14 rewards: false
15 }
16 ]
17 }),
18});
19const { result } = await response.json();
20console.log("Block hash:", result.blockhash);Python
1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4 "jsonrpc": "2.0",
5 "id": 1,
6 "method": "getBlock",
7 "params": [
8 166974442,
9 {
10 "encoding": "jsonParsed",
11 "maxSupportedTransactionVersion": 0,
12 "transactionDetails": "full",
13 "rewards": False
14 }
15 ]
16})
17result = response.json()["result"]
18print(f"Block hash: {result['blockhash']}")Rust
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": "getBlock",
12 "params": [
13 166974442_u64,
14 {"encoding": "jsonParsed", "maxSupportedTransactionVersion": 0, "transactionDetails": "full", "rewards": false}
15 ]
16 }))
17 .send().await?
18 .text().await?;
19 println!("{}", res);
20 Ok(())
21}Example Response
1{
2 "jsonrpc": "2.0",
3 "result": {
4 "blockhash": "3Eq21vXNB5s86c62bVuUfTeaMif1N2kUqRPBmGRJhyTA",
5 "previousBlockhash": "mfcyqEXB3DnHXki6KjjmZck6YjmZLvpAByy2fj4nh6B",
6 "parentSlot": 166974441,
7 "transactions": [],
8 "blockTime": 1681391935,
9 "blockHeight": 150676031
10 },
11 "id": 1
12}