circle-infogetBlock

Learn getBlock use cases, code examples, request parameters, response structure, and tips. Ask ChatGPT

The getBlock RPC method allows you to retrieve detailed information about a confirmed block in the Solana ledger. This is essential for block explorers, transaction history analysis, and understanding the state of the chain at a specific point in time.


Common Use Cases

  • Inspecting Block Contents View all transactions included in a specific block.

  • Retrieving Block Hashes Get the blockhash for a given slot, its parent’s blockhash, and its parent slot.

  • Checking Block Height and Time Find out a block’s height (its sequence number) and its estimated production time.

  • Analyzing Transaction Details With appropriate parameters, retrieve full transaction data, including metadata like fees, status, pre/post balances, and inner instructions.

  • Fetching Rewards Optionally include reward information for the block.


Parameters

  • slot (number, required): The slot number of the block to query (u64).

  • config (object, optional): Configuration options include:

    • commitment (string): Commitment level. processed is not supported. Defaults to finalized.

    • encoding (string): How transaction data is returned. Defaults to json if transactionDetails is full or accounts, otherwise base64. Options:

      • json (deprecated)

      • jsonParsed (recommended for parsed keys and Lookup Table support)

      • base58

      • base64

      • base64+zstd

    • transactionDetails (string): Level of transaction detail to return. Defaults to full.

      • full

      • accounts

      • signatures

      • none

    • rewards (boolean): Include rewards array if true. Defaults to false.

    • maxSupportedTransactionVersion (number): Maximum transaction version to return. Set to 0 to include versioned transactions using Address Lookup Tables.


Response

If the block is found and confirmed, the result will include:

  • blockhash (string): The base-58 encoded blockhash.

  • previousBlockhash (string): The base-58 encoded blockhash of the previous block.

  • parentSlot (number): The slot number of the parent block.

  • transactions (array): List of transactions included in the block. Each entry contains:

    • meta: Transaction metadata (e.g., fee, logs, balances).

    • transaction: The raw transaction data, including signatures and message content.

  • rewards (array, optional): Present if rewards: true was requested. Includes reward info (e.g., pubkey, lamports, postBalance, rewardType, and commission).

  • blockTime (number | null): Estimated Unix timestamp of block production.

  • blockHeight (number | null): Sequence number from genesis slot.

If the block is not found or unconfirmed, result will be null.


Example: Fetching Block Information

Here’s how to retrieve block info for a sample slot (e.g., 355184627) on Devnet. Replace it with a current confirmed slot number for accurate results. Also, replace X-API-KEY with your actual CoinVera API key.

Example Response

Developer Tips

  • Slot vs. Block Height The getBlock method accepts a slot number, not a block height. While slots are generally sequential, some may be skipped by the validator leader. To get the actual block sequence number, refer to the blockHeight field in the response.

  • maxSupportedTransactionVersion Is Crucial To retrieve blocks containing versioned transactions (now standard and using Address Lookup Tables), you must specify: "maxSupportedTransactionVersion": 0 Omitting this may lead to errors when querying modern blocks.

  • Choosing transactionDetails Level:

    • full: For comprehensive analysis—returns the most complete data including metadata.

    • signatures: Best for listing only transaction signatures in a block.

    • accounts: A good middle ground—lists involved accounts without full instructions.

    • none: Use when you only need high-level block metadata like blockhash or rewards.

  • Use jsonParsed for Encoding When requesting transaction details, jsonParsed is the recommended format. It provides a structured, human-readable JSON output and supports address resolution from Lookup Tables. Avoid using json (deprecated), as it lacks modern feature support.

  • Block Unavailability Handling A null response can mean:

    • The slot was skipped.

    • The block hasn’t reached the requested commitment level.

    • The RPC node (e.g., CoinVera) has pruned the block due to ledger limits—common with older historical data.

  • Include Rewards When Needed To retrieve block reward distribution info (e.g., for validators and stakers), set: "rewards": true This increases response size but is essential for full reward visibility.

Last updated