getLeaderSchedule
Returns the leader schedule for the epoch that contains the supplied slot, or for the current epoch if no slot is supplied.
Request
Send a JSON-RPC 2.0 POST request with method: "getLeaderSchedule". The params array takes an optional slot (or null) and an optional configuration object.
{ "jsonrpc": "2.0", "id": 1, "method": "getLeaderSchedule", "params": [ null, { "commitment": "processed", "identity": "dv2eQHeP4RFrJZ6UeiZWoc3XTtmtZCUKxxCApCDcRNV" } ]}@solana/kit
import { address, createSolanaRpc, type Commitment } from "@solana/kit"; const rpc_url = "https://rpc.openinfra.sh";const rpc = createSolanaRpc(rpc_url); let slotNumber = null; let identity = address("dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92");let commitment: Commitment = "finalized"; let leaderSchedule = await rpc .getLeaderSchedule(slotNumber, { identity, commitment }) .send(); console.log(leaderSchedule);@solana/web3.js
import { Connection, clusterApiUrl } from "@solana/web3.js"; const connection = new Connection("https://rpc.openinfra.sh", "confirmed"); let leaderSchedule = await connection.getLeaderSchedule(); console.log(leaderSchedule);Rust
use anyhow::Result;use solana_client::{nonblocking::rpc_client::RpcClient, rpc_config::RpcLeaderScheduleConfig};use solana_commitment_config::CommitmentConfig; #[tokio::main]async fn main() -> Result<()> { let client = RpcClient::new_with_commitment( String::from("https://rpc.openinfra.sh"), CommitmentConfig::confirmed(), ); let slot_number = None; let config = RpcLeaderScheduleConfig { identity: String::from("dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92").into(), commitment: CommitmentConfig::finalized().into(), }; let leader_schedule = client .get_leader_schedule_with_config(slot_number, config) .await?; println!("{:#?}", leader_schedule); Ok(())}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| slot | u64 | object | null | No | Either the slot used to select the epoch, null to use the current slot at the requested commitment, or a configuration object. If a number, the RPC returns the schedule for the epoch containing that slot. If null or omitted, uses the current epoch. If an object, it has the same shape as config and the slot is omitted. |
| config | object | No | Configuration object. Only used when slot is a number or null. |
| config.commitment | string | No | Commitment level used to select which slot the node reads from. Accepted values: processed, confirmed, finalized (default). |
| config.identity | string | No | Return only entries for this validator identity, as a base-58 encoded string. |
slot as an object
When slot is passed as an object instead of a number or null, it acts as the configuration and the separate config parameter is omitted. The object supports the following fields:
| Field | Type | Description |
|---|---|---|
| commitment | string | Commitment level used to select which slot the node reads from for this request. |
| identity | string | Validator identity to filter for, as a base-58 encoded string. |
commitment values
| Value | Description |
|---|---|
| processed | Return data from the highest slot this node has processed on the fork it currently considers best. This is the newest view, but it can still change if the cluster switches forks. |
| confirmed | Return data from the highest slot that at least two-thirds of active stake has directly voted to confirm. This is more stable than processed, but it is still a weaker guarantee than finalized. |
| finalized | Return data from the highest slot that the cluster recognizes as finalized. In practice, this means the slot has reached maximum vote lockout in validators' vote towers and is recognized by at least two-thirds of active stake. This is the strongest commitment level. |
Response
{ "jsonrpc": "2.0", "result": { "4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 ] }, "id": 1}The result is null when the requested epoch is not available. Otherwise it is an object where each key is a validator identity (base-58 encoded) and each value is an array of slot indices relative to the first slot of the requested epoch.
| Field | Type | Description |
|---|---|---|
| result | object | null | Returns null if the requested epoch is unavailable. Otherwise an object whose keys are validator identities (base-58 encoded strings) and whose values are arrays of leader slot indices relative to the first slot in the requested epoch. |
| <identity> | number[] | Array of slot indices (relative to the epoch's first slot) at which this validator is scheduled to be the leader. |