With examples in curl and Python
getBlock
is a core Solana RPC method that can dramatically impact performance if misused; don’t pull more data than you need.json
, jsonParsed
, base58
, or base64
encoding strategically; always enable compression (gzip
) to reduce huge payloads.getBlock
efficiently, with practical examples in Python and curl.
getBlock
method returns detailed information about a confirmed block in Solana’s ledger. A block in Solana contains:
blockhash
— the unique hash (ID) of this block (base-58 encoded)previousBlockhash
— the hash of the parent blockparentSlot
— the slot number of the parent blockblockHeight
— the sequential block height (the number of blocks beneath this block)blockTime
— the timestamp when the block was produced, which is yet another trick. See Solana: Understanding block time.transactions
— an array of transactions in the block (if requested)signatures
— an array of transaction signatures in the block (if requested)rewards
— an array of block rewards (if requested)getBlock
, you can specify several parameters to control what data you receive:
commitment
— finalized
(default) or confirmed
encoding
— json
(default), jsonParsed
, base64
, or base58
.transactionDetails
— full
(default), accounts
, signatures
, or none
rewards
— boolean to include block rewardsmaxSupportedTransactionVersion
— for handling versioned transactionsjsonParsed
, which produces the largest output on the node side and gets transported to you. You should never do this in production with a heavy load. This more of a one-off inspection call than anything else.params
as above. Make sure you stay within the last 20 hours or so, unless you want to use an archive call, which is also fine as Chainstack is extremely affordable & transparent with pricing — a full node request is counted as one request, and an archive node request is counted as 2 requests, and that’s it.
getBlock
method due to the large size of block data. Here’s why compression is essential and how to implement it:
Accept-Encoding: gzip
header and the --compressed
flag:
Accept-Encoding: gzip
header tells the server you can handle compressed responses--compressed
flag tells curl to automatically decompress the data on receiptAccept-Encoding: gzip
block_data.gz
file:
block_data.gz
to block_data.json
.
headers={"Accept-Encoding": "gzip"}
or set requests.get(..., stream=True)
getBlock
RPC method, especially for blocks with many transactions. So use compression.
getBlock
call with "encoding": "base58"
or "encoding": "base64"
, you are getting the respective encoding on the transaction level, not the entire block. In other words, you will still get back a JSON response, it’s only the transaction data that will be encoded in base58
or base64
.
Let’s explore each option:
json
encoding provides transaction data in a standard JSON format with binary data encoded as base58 strings.
jsonParsed
encoding goes beyond standard JSON by attempting to decode instruction data into human-readable format:
base58
encoding returns binary data for transactions as base58-encoded strings:
base64
encoding returns binary data for transactions as base64-encoded strings:
Encoding | Size | Human Readability | Parsing Complexity | Use Case |
---|---|---|---|---|
json | Medium | Good | Low | General purpose |
jsonParsed | Largest | Best | Lowest | Analysis & debugging |
base58 | Medium-Large | Poor | Medium | Ecosystem compatibility |
base64 | Smallest | Poor | Medium | Performance & storage |
pip install solana
.
slots_to_fetch = [329849011, 329849012, 329849013, 329849014, 329849015]
.
Recommended encodings:
json
(good balance of size and parsing speed)jsonParsed
(larger but provides decoded instruction data)base64
(efficient for storage and transmission)encoding="json"
use encoding="base64"
.
getBlock
RPC method efficiently requires understanding both what data you need and how to optimize your requests. By following the best practices outlined in this guide—using compression, limiting concurrency, using block ranges, requesting only what you need, and implementing proper error handling—you can build robust applications that interact with Solana blocks effectively.
Remember these key takeaways:
json
, jsonParsed
, base58
, base64
.