voteSubscribe – Solana

The voteSubscribe RPC Solana method allows clients to subscribe to notifications whenever a new vote is observed in gossip.

Unstable Method

This subscription is unstable and only available if the validator was started with the --rpc-pubsub-enable-vote-subscription flag. The format of this subscription may change in future Solana updates.

Supported Networks

  • Mainnet

  • Devnet

Parameters

None: This method does not require any parameters.

Result

Returns an integer representing the subscription ID, which is required for unsubscribing.

Result Format

  • integer: The subscription ID.

Request Example

API Endpoints

wss://go.getblock.io/<ACCESS-TOKEN>/

JSON-RPC Request

wscat -c "wss://go.getblock.io/<ACCESS-TOKEN>/" --exec '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "voteSubscribe"
}'

Response

A successful request returns a subscription ID.

Example Response

{
  "jsonrpc": "2.0",
  "result": 0,
  "id": 1
}

In this response:

  • result: 0 represents the assigned subscription ID.

Notification Format

Upon vote updates, clients receive notifications containing vote details.

Example Notification

{
  "jsonrpc": "2.0",
  "method": "voteNotification",
  "params": {
    "result": {
      "hash": "8Rshv2oMkPu5E4opXTRyuyBeZBqQ4S477VG26wUTFxUM",
      "slots": [1, 2],
      "timestamp": null
    },
    "subscription": 0
  }
}

Notification Fields

  • hash (string): The vote hash.

  • slots (array): The slots covered by the vote, represented as an array of u64 integers.

  • timestamp (i64|null): The timestamp of the vote. It may be null if unavailable.

  • signature (string): The signature of the transaction that contained this vote.

  • votePubkey (string): The public key of the vote account, encoded in base-58.

Error Handling

Common voteSubscribe error scenarios:

  • Network issues: Problems with the Solana JSON-RPC API endpoints.

  • Invalid WebSocket connection: Issues maintaining a stable connection.

  • Subscription failure: If the validator was not started with the required flag.

Example Error Response

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32000,
    "message": "WebSocket connection error"
  },
  "id": 1
}

Use Cases

The Solana voteSubscribe method is useful for:

  • Tracking real-time validator votes in the Solana network.

  • Monitoring voting behavior for governance and security purposes.

  • Analyzing vote distribution across slots.

  • Building dApps that require real-time voting updates.

  • Ensuring applications stay in sync with validator activities.

Code voteSubscribe Example – Web3 Integration

const WebSocket = require('ws');

const ws = new WebSocket("wss://go.getblock.io/<ACCESS-TOKEN>/");

ws.on('open', () => {
  const payload = {
    jsonrpc: "2.0",
    id: 1,
    method: "voteSubscribe"
  };
  ws.send(JSON.stringify(payload));
});

ws.on('message', (data) => {
  console.log("Vote Notification:", JSON.parse(data));
});

ws.on('error', (error) => {
  console.error("WebSocket error:", error.message);
});

ws.on('close', () => {
  console.log("WebSocket connection closed");
});

Integration with Web3

By integrating Web3 voteSubscribe into Solana's Core API, developers can:

  • Monitor validator votes in real-time.

  • Improve blockchain tracking systems.

  • Enhance dApps with live vote updates.

  • Ensure applications remain synchronized with validator activities.

  • Optimize governance tools by tracking consensus formation.

This method is a critical component of the Core API that enables efficient vote tracking, request handling, and transaction validation in Solana-based applications.

Last updated