Replaying Slots with Solana yellowstone gRPCs
Start streaming data from a specific slot when establishing a new gRPC connection or reconnecting
Last updated
Was this helpful?
Start streaming data from a specific slot when establishing a new gRPC connection or reconnecting
Last updated
Was this helpful?
Reconnect mechanisms are important for production applications β we donβt want to miss any data due to temporary network issues. But sometimes, reconnecting alone isnβt enough. We also need to replay data from a specific slot, especially if a stream drops during critical updates. Yellowstone gRPC supports this via the fromSlot
field in the subscription request. By storing the last received slot and including it in the next subscription, you can ensure your stream resumes from where it left off β without missing a single block or transaction.
At any given time, the earliest available slot for replay is approximately 150 slots older than the current slot.
The example below illustrates how you can replay from a specific slot upon disconnection. You can paste this code in Replit to see it in action, or simply run the Repl .
The above example implements a robust mechanism to reconnect to the gRPC stream and replay from the last known slot to avoid missing any data.
Reconnection:
If the stream encounters an error (like a network drop), the stream automatically retries after waiting a short time (denoted by theRETRY_DELAY_MS
variable). This loop ensures the stream keeps trying to reconnect without manual restart.
Replay from Last Slot:
Before each retry, the app checks if it previously received any transaction data. If so, it stores the latest slot
number (lastSlot
). When reconnecting, it includes this lastSlot
in the fromSlot
field of the SubscribeRequest
, telling Yellowstone gRPC to resume streaming from that exact slot, not from the current blockchain tip.
The complete code of implementing a reconnection mechanism is available on and .