getBlock
Overview
The getBlock JSON-RPC method is a fundamental tool for Solana developers and data analysts, enabling the retrieval of comprehensive information about a specific block on the Solana blockchain. Given a slot number, this method returns a structured object containing details such as the block's hash, its parent's slot and hash, a timestamp, and crucially, an array of all transactions processed within that block, along with any associated rewards.
This method is essential for constructing blockchain explorers, developing indexing services, performing historical data analysis, and auditing on-chain activity. It provides a granular view of the state transitions and events that occurred during a particular slot, offering deep insights into network operations and program execution. By allowing customization of transaction encoding and detail levels, getBlock can be tailored for various use cases, from lightweight signature retrieval to exhaustive analysis of program logs and inner instructions.
Understanding the output of getBlock is paramount for debugging smart contracts, analyzing network congestion, tracking token movements, and verifying the integrity of the blockchain state. Its ability to expose all transactions in a block, including vote transactions and detailed metadata, makes it a cornerstone for applications requiring full historical context and transparent access to the Solana ledger.
Parameters
| Name | Type | Required/Optional | Description |
|---|---|---|---|
slot | number | Required | The slot number of the block to retrieve. |
config | object | Optional | Configuration object for customizing the response. |
config.encoding | string | Optional | Default: json. Encoding for transaction details. Valid values: json, jsonParsed, base58, base64, base64+zstd. jsonParsed is highly recommended for human readability and detailed program log analysis, as it attempts to parse instruction data and account keys. |
config.transactionDetails | string | Optional | Default: full. Level of transaction detail to return. Valid values: full, signatures, accounts, none. full returns all transaction components and metadata; signatures only returns transaction hashes (signatures); accounts returns transaction details but filters out program logs and inner instructions for non-involved accounts; none returns no transaction information. |
config.rewards | boolean | Optional | Default: true. Whether to return rewards information for the block. |
config.commitment | string | Optional | Default: finalized. The level of commitment desired for the block. Valid values: processed, confirmed, finalized. finalized implies the block is irreversible; confirmed means it has been voted on by a supermajority; processed means the node has processed it. |
config.maxSupportedTransactionVersion | number or string | Optional | Default: 0. The maximum transaction version to return. Set to 0 for legacy (v0) transactions, or latest to include all currently supported transaction versions (e.g., v0, v1, etc.). If omitted or set to 0, only transactions with version 0 or earlier will be returned. This is crucial for retrieving V0 Message transactions. |
config.vote | boolean | Optional | Default: false. If true, vote transactions are included in the transactions array. |
config.showRewardsIfNoTransactions | boolean | Optional | Default: false. If true, rewards are returned even if transactionDetails is none. Requires rewards: true. |
Expected Response
The getBlock method returns a JSON object representing the requested block. The structure and content of this object, particularly for transactions, are highly dependent on the config parameters provided in the request.
1{
2 "jsonrpc": "2.0",
3 "result": {
4 "blockhash": "HnHvW9E44wXNnF9yHhD4xQ7z4S4vD5F2T8L9B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8S9T0U1V2W3X4Y5Z",
5 "blockHeight": 123456789,
6 "blockTime": 1678886400,
7 "parentSlot": 123456788,
8 "previousBlockhash": "A1B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8S9T0U1V2W3X4Y5Z5Y4X3W2V1U0T9S8R7Q6P5O4N3M2L1K0J9I8H7G6F5E4D3C2B1A",
9 "rewards": [
10 {
11 "pubkey": "VoteAccountPublicKey111111111111111111111111111111111111",
12 "lamports": 5000000,
13 "postBalance": 10000000000,
14 "rewardType": "staking",
15 "commission": 10
16 },
17 {
18 "pubkey": "FeePayerPublicKey111111111111111111111111111111111111",
19 "lamports": 5000,
20 "postBalance": 9999999995000,
21 "rewardType": "fee",
22 "commission": null
23 }
24 ],
25 "transactions": [
26 {
27 "meta": {
28 "err": null,
29 "fee": 5000,
30 "preBalances": [2000000000, 1000000000],
31 "postBalances": [1999995000, 1000000000],
32 "logMessages": [
33 "Program BPF Loader 1111111111111111111111111111111111 invoke [1]",
34 "Program log: Instruction: Transfer",
35 "Program BPF Loader 1111111111111111111111111111111111 success"
36 ],
37 "innerInstructions": [],
38 "loadedAddresses": {
39 "writable": [],
40 "readonly": []
41 },
42 "rewards": null,
43 "status": { "Ok": null },
44 "computeUnitsConsumed": 200,
45 "computeUnitsElevated": 0,
46 "returnData": null
47 },
48 "transaction": {
49 "signatures": [
50 "5ZtM3D7gP4U5Q6R7S8T9U0V1W2X3Y4Z5A6B7C8D9E0F1G2H3I4J5K6L7M8N9O0P1Q"
51 ],
52 "message": {
53 "accountKeys": [
54 "AccountKey111111111111111111111111111111111111",
55 "AccountKey222222222222222222222222222222222222",
56 "VoteAccountKey111111111111111111111111111111111"
57 ],
58 "header": {
59 "numReadonlySignedAccounts": 0,
60 "numReadonlyUnsignedAccounts": 1,
61 "numRequiredSignatures": 1
62 },
63 "instructions": [
64 {
65 "programId": "11111111111111111111111111111111",
66 "accounts": [0, 1],
67 "data": "3Bxs1kP9N93y"
68 }
69 ],
70 "recentBlockhash": "HnHvW9E44wXNnF9yHhD4xQ7z4S4vD5F2T8L9B2C3D4E5F6G7H8I9J0K1L2M3N4O5P6Q7R8S9T0U1V2W3X4Y5Z",
71 "addressTableLookups": null
72 }
73 },
74 "version": "legacy"
75 }
76 ]
77 },
78 "id": 1
79}The top-level result object contains the following properties:
blockhash:string- The base58-encoded hash of the requested block.
blockHeight:number | null- The height of the block. This indicates its position in the longest confirmed chain. Will be
nullfor blocks older thanMAX_BLOCK_HEIGHT_AGE(approximately 31M slots).
- The height of the block. This indicates its position in the longest confirmed chain. Will be
blockTime:number | null- The Unix timestamp (in seconds since the epoch) of when the block was processed by the cluster leader. Will be
nullfor blocks older thanMAX_BLOCK_HEIGHT_AGE.
- The Unix timestamp (in seconds since the epoch) of when the block was processed by the cluster leader. Will be
parentSlot:number- The slot number of the block's parent.
previousBlockhash:string- The base58-encoded hash of the block's parent.
rewards:array<object> | null- An array of reward objects. This property is present if
config.rewardsistrue. Each object within the array represents a reward distribution and contains:pubkey:string- The base58-encoded public key of the account that received the reward.lamports:number- The amount of lamports received as a reward.postBalance:number- The account's balance in lamports after the reward was applied.rewardType:string- The type of reward. Possible values includefee,rent,staking,voting.commission:number | null- The vote account commission applied to the reward (0-100), if applicable (e.g., for staking rewards).nullotherwise.
- An array of reward objects. This property is present if
transactions:array<object> | null- An array of transaction objects. This property is present unless
config.transactionDetailsisnone. The structure of each transaction object is complex and varies based onconfig.encodingandconfig.transactionDetails. - Each object in
transactionstypically contains:transaction:object | string- Represents the serialized transaction data.
- If
config.encodingisjsonorjsonParsed, it's an object with:signatures:array<string>- An array of base58-encoded transaction signatures.message:object- The transaction's message.accountKeys:array<string>- An array of base58-encoded public keys for all accounts involved in the transaction.header:object- Describes the transaction's signature requirements:numReadonlySignedAccounts:numbernumReadonlyUnsignedAccounts:numbernumRequiredSignatures:number
instructions:array<object>- An array of instructions that make up the transaction.- Each instruction contains
programId(the program ID for the instruction),accounts(indices into theaccountKeysarray), anddata(base58 or base64 encoded instruction data). - If
jsonParsedencoding is used, instructions will be parsed into a more human-readable format, often includingprogram(program name),parsed(parsed instruction data), andtype.
- Each instruction contains
recentBlockhash:string- The base58-encoded recent blockhash used for the transaction.addressTableLookups:array<object> | null- For V0 transactions, this array details which address lookup tables were used and which accounts were loaded from them, separated intowritableandreadonlyarrays of base58-encoded public keys.nullfor legacy (v0) transactions without lookups or ifmaxSupportedTransactionVersionis not high enough.
- If
config.encodingisbase58,base64, orbase64+zstd,transactionwill be astringrepresenting the serialized transaction in the specified encoding.
meta:object | null- Transaction metadata.
nullif the transaction failed to parse, or ifconfig.transactionDetailsissignaturesornone. err:object | null- Error object if the transaction failed, otherwisenull.fee:number- The transaction fee in lamports.preBalances:array<number>- Account balances in lamports before the transaction.postBalances:array<number>- Account balances in lamports after the transaction.logMessages:array<string> | null- Program log messages generated during transaction execution.nullifconfig.encodingis notjsonParsedorconfig.transactionDetailsis notfull.innerInstructions:array<object> | null- Details of Cross-Program Invocations (CPIs).nullifconfig.encodingis notjsonParsedorconfig.transactionDetailsis notfull.loadedAddresses:object | null- For V0 transactions, this object lists addresses loaded from address lookup tables by the transaction, categorized intowritableandreadonlyarrays of base58-encoded public keys.nullfor legacy (v0) transactions without lookups.rewards:array<object> | null- Rewards specific to this transaction, often consolidated into the top-levelrewardsarray.status:object- An object indicating the transaction's success ({"Ok":null}) or failure ({"Err": ...}).computeUnitsConsumed:number | null- The total compute units consumed by the transaction.nullif not available.computeUnitsElevated:number | null- The total compute units elevated for the transaction (relevant for advanced fee models).nullif not available.returnData:object | null- The return data from the last instruction in the transaction. ContainsprogramId(base58-encoded program ID) anddata(base64-encoded byte array).nullif no return data.
- Transaction metadata.
version:string | number | null- The transaction message version. Will be"legacy"for transactions without a specified version or the specific version number (e.g.,0) for V0 Message transactions.nullif the transaction cannot be parsed.
- An array of transaction objects. This property is present unless
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: "getBlock",
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": "getBlock",
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": "getBlock",
12 "params": [] // Add relevant parameters here
13 }))
14 .send()
15 .await?
16 .text()
17 .await?;
18
19 println!("{}", res);
20 Ok(())
21}