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.
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”.
result
- An integer subscription id (needed to unsubscribe)
subscription
- An object containing block information:
slot
- The slot number of this block
blockhash
- The hash of this block as a base-58 encoded string
previousBlockhash
- The blockhash of this block’s parent as a base-58 encoded string
parentSlot
- The slot number of this block’s parent
transactions
- 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 processedrewards
- 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 examplesnpm install -g wscat
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:
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.
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.