For the complete documentation index, see llms.txt. This page is also available as Markdown.

getSlotLeaders - Solana

Example code for the getSlotLeaders JSON-RPC method. Complete guide on how to use the getSlotLeaders JSON-RPC method in the GetBlock Web3 documentation.

This method returns the identity Pubkey of the scheduled leader for each slot in a contiguous range. A maximum of 5,000 slots can be requested per call.

Parameters

Parameter
Type
Required
Description

startSlot

number

Yes

First slot of the range, inclusive

limit

number

Yes

Number of slots to return, between 1 and 5000

Request

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "getSlotLeaders",
    "params": [397234561, 4],
    "id": "getblock.io"
}'
example.js
const { Connection } = require('@solana/web3.js');

const connection = new Connection('https://go.getblock.io/<ACCESS-TOKEN>/', 'confirmed');

const leaders = await connection.getSlotLeaders(397234561, 4);

console.log(leaders.map((l) => l.toBase58()));
example.py
import requests

response = requests.post(
    'https://go.getblock.io/<ACCESS-TOKEN>/',
    headers={'Content-Type': 'application/json'},
    json={
        'jsonrpc': '2.0',
        'method': 'getSlotLeaders',
        'params': [397234561, 4],
        'id': 'getblock.io'
    }
)

print(response.json()['result'])

Response

{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": [
        "dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92",
        "dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92",
        "dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92",
        "dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92"
    ]
}

Response Parameters

Parameter
Type
Description

jsonrpc

string

JSON-RPC protocol version ("2.0")

id

string

Request identifier matching the request

result

array

Array of leader identity Pubkeys, one per slot in the requested range

Use Cases

  • Leader Prefetch: Warm connections to the next few leaders before sending

  • Send Fanout: Broadcast a transaction to several upcoming leaders at once

  • Rotation Analysis: Observe the four-slot leader rotation pattern directly

  • Operator Alerts: Notify an operator shortly before its leader slots begin

Error Handling

Error Code
Message
Description

-32602

Invalid params

Limit exceeds 5000 or the range extends beyond the known schedule

-32603

Internal error

Node failed to read the leader schedule for the range

-32005

Node is unhealthy

The node has fallen behind the cluster tip

Was this helpful?