The slotSubscribe
method in Solana allows developers to receive real-time notifications about slot updates. This subscription-based method provides updates whenever a new slot is processed by the node.
Parameters
None. This method does not accept any parameters.
Response
result
- An integer subscription id (needed to unsubscribe)subscription
- An object containing slot information:slot
- The current slot heightparent
- The parent slot heightroot
- The current root slot heightstatus
- The processing status of the slot:"processed"
- Slot has been processed"confirmed"
- Slot has been confirmed"finalized"
- Slot has been finalized
slotSubscribe
code examples
slotSubscribe
code examplesThis example subscribes to slot updates.
Note 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":"slotSubscribe"}
Use case
The slotSubscribe
method is essential for applications that need to monitor the progress of the Solana blockchain. Common use cases include:
- Block height tracking: Monitor the current slot height of the blockchain
- Chain progress monitoring: Track the advancement of processed, confirmed, and finalized slots
- Timing operations: Coordinate operations based on slot progression
- UI updates: Update user interfaces with current blockchain progress
- Performance monitoring: Track slot processing times and chain progress rates
By subscribing to slot updates, applications can maintain accurate information about the current state of the blockchain and coordinate operations based on slot progression.