rootSubscribe | Solana

The rootSubscribe method in Solana allows developers to receive real-time notifications about changes to the root of the ledger. This subscription-based method provides updates whenever a new root is set.

Parameters

  • <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 root information:
    • root - The slot number that has been rooted
    • timestamp - The estimated production time of the rooted slot, as Unix timestamp (seconds since the Unix epoch)

rootSubscribe code examples

This example subscribes to root 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": "rootSubscribe" }

Use case

The rootSubscribe method is particularly useful for applications that need to monitor the finality of the Solana blockchain. Common use cases include:

  • Finality tracking: Monitor when slots become rooted (finalized) in the blockchain
  • Chain reorganization detection: Track changes in the root to detect potential chain reorganizations
  • Historical data processing: Know when slots are safe to process for historical data analysis
  • Consensus monitoring: Track the progress and health of consensus by monitoring root advancement

By subscribing to root updates, applications can maintain accurate information about the finalized state of the blockchain and make decisions based on confirmed data.