The blockSubscribe
method in Solana allows developers to receive real-time notifications about new blocks on the Solana blockchain. This subscription-based method provides updates whenever new blocks are added to the chain.
Get your own Solana node endpoint today
Start for free and get your app to production levels immediately. No credit card required.
You can sign up with your GitHub, X, Google, or Microsoft account.
Parameters
filter
- An object specifying the type of information to receive:mentionsAccountOrProgram
- A public key as a base-58 encoded string. Returns notifications only when the specified account or program ID is part of the transaction.slot
- Only return notifications for blocks starting from this slot.
<commitment>
- (optional) The level of commitment desired when querying state. Default is "finalized".
Response
result
- An integer subscription id (needed to unsubscribe)subscription
- An object containing block information:slot
- The slot number of this blockblockhash
- The hash of this block as a base-58 encoded stringpreviousBlockhash
- The blockhash of this block's parent as a base-58 encoded stringparentSlot
- The slot number of this block's parenttransactions
- An array of transaction information:transaction
- Transaction object, either in JSON format or base-58 encoded binary data if "encoding" parameter is set to "base58"meta
- Transaction status metadata object:err
- Error if transaction failed, null if transaction succeededstatus
- Transaction status, either{Ok: null}
or{Err: <ERR>}
fee
- Fee this transaction was charged, as u64 integerpreBalances
- Array of u64 account balances from before the transaction was processedpostBalances
- Array of u64 account balances after the transaction was processed
rewards
- Block reward details (if requested):pubkey
- The public key of the account that received the reward, as a base-58 encoded stringlamports
- The number of lamports rewardedpostBalance
- The new balance of the account in lamportsrewardType
- The type of reward: "fee", "rent", "voting", "staking"
blockTime
- Estimated production time, as Unix timestamp (seconds since the Unix epoch)blockHeight
- The number of blocks beneath this block
blockSubscribe
code examples
blockSubscribe
code examplesNote that subscriptions require a WebSocket connection and WebSocket cat for you to use this method in the console.
Install WebSocket cat with:
npm install -g wscat
$ wscat -c YOUR_CHAINSTACK_WEBSOCKET_ENDPOINT
# Wait for the connection to be established
Connected (press CTRL+C to quit)
> {"jsonrpc":"2.0","id":"1","method":"blockSubscribe","params":["all",{"encoding":"json","maxSupportedTransactionVersion":0,"transactionDetails":"full","rewards":false}]}
$ wscat -c YOUR_CHAINSTACK_WEBSOCKET_ENDPOINT
# Wait for the connection to be established
Connected (press CTRL+C to quit)
> {"jsonrpc":"2.0","id":"1","method":"blockSubscribe","params":[{"mentionsAccountOrProgram":"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"},{"commitment":"confirmed","encoding":"base64","showRewards":false,"transactionDetails":"full","maxSupportedTransactionVersion":0}]}
Examples:
- wscat, all — generates a stream of all blocks with full transaction details in the blocks
- wscat, program id — generates a stream only of the transactions that involve the pump.fun program id.
Use blockUnsubscribe | Solana to remove the subscription.
Use case
The blockSubscribe
method in Solana is used to subscribe to the network and receive real-time updates on new blocks added to the chain. This can be useful in various real-world scenarios, including:
-
Decentralized applications (dApps): dApps can use this method to stay synchronized with the latest state of the blockchain. By receiving notifications about new blocks, they can update their internal state and provide users with the most current information.
-
Block explorers: Block explorer services can utilize this method to receive instant notifications about new blocks, allowing them to update their displays in real-time and provide users with the most up-to-date blockchain information.
-
Trading bots: Automated trading systems can use the
blockSubscribe
method to receive timely information about new transactions and blocks. This can help in making quick trading decisions based on the latest blockchain activity. -
Wallet services: Wallet providers can use this method to monitor the blockchain for transactions involving their users' accounts, enabling them to provide instant notifications and balance updates.
-
Analytics platforms: Blockchain analytics services can use this subscription to gather real-time data about network activity, transaction volumes, and other metrics to provide insights into the Solana ecosystem.
By subscribing to the blockSubscribe
method, applications can receive instant updates about new blocks, allowing them to react quickly to changes on the Solana blockchain and provide a more responsive user experience.