getSlotLeader

Learn about getSlotLeader—its use cases, code examples, request parameters, response structure, and practical tips.

The getSlotLeader RPC method in CoinVera returns the public key of the validator currently designated as the block producer for the current slot. This determination is made according to the node’s view at a specified commitment level.


✅ Common Use Cases

  • Identifying the Current Block Producer Determine which validator is currently responsible for producing blocks.

  • Network Monitoring Track how slot leadership rotates among validators.

  • Debugging Transaction Issues In advanced setups, it may be useful to identify the leader—especially when submitting transactions directly to leader nodes.


🧾 Request Parameters

getSlotLeader accepts an optional configuration object:

  • options (object, optional):

    • commitment (string): One of finalized, confirmed, or processed. Defaults to the node’s standard (usually finalized).

    • minContextSlot (number): Minimum slot the request must be evaluated at. Ensures the node is sufficiently up to date before responding.


📦 Response Structure

Returns a single base-58 encoded public key string representing the current slot leader.

{
  "result": "5Y6g8zWcR9GVoHqGnBbPmgzUdu1tHuCVDRKLv7fP5Xed"
}

🧪 Examples

1. Get Current Slot Leader (Default Commitment)

Fetches the current leader using the node's default commitment (usually finalized).

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getSlotLeader"
}

2. Get Slot Leader with confirmed Commitment

Fetches the leader for the most recently confirmed slot.

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getSlotLeader",
    "params": [
      {
        "commitment": "confirmed"
      }
    ]
}

Code Examples

const fetch = require('node-fetch');

async function getSlotLeader(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getSlotLeader',
        "params": [
            {
              "commitment": "confirmed"
            }
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

getSlotLeader(RPC_URL);

Example Response

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

💡 Developer Tips

  • Leaders Rotate Rapidly Slot leaders change roughly every 4 slots, making the returned value a momentary snapshot.

  • Commitment Level Impacts Accuracy

    • processed: Most recent view, may be unstable.

    • confirmed or finalized: Safer, more consistent results.

  • Understand Leader Scheduling The rotation is based on a leader schedule, calculated at the start of each epoch. For future or historical slots, use getLeaderSchedule.

  • Node Perspective Matters Each RPC node operates based on its own network view. Results may vary slightly across nodes due to latency or forks.


The getSlotLeader method provides a fast and simple way to identify the current validator responsible for producing blocks. For a broader perspective of validator rotation, use the more detailed getLeaderSchedule RPC method.

Last updated