> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# getLeaderSchedule

> Returns the leader schedule for the epoch that contains the supplied slot, or for the current epoch if no slot is supplied.

<Info>
  **Source**

  [`get_leader_schedule`](https://github.com/anza-xyz/agave/blob/v4.3.2/rpc/src/rpc.rs#L2990)
</Info>

<RequestExample>
  ```bash cURL
  curl https://api.devnet.solana.com -s -X POST \
    -H "Content-Type: application/json" \
    -d '
    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getLeaderSchedule",
      "params": [
        null,
        {
          "commitment": "processed",
          "identity": "dv2eQHeP4RFrJZ6UeiZWoc3XTtmtZCUKxxCApCDcRNV"
        }
      ]
    }
  '
  ```

  ```ts Kit
  import { address, createSolanaRpc, type Commitment } from "@solana/kit";

  const rpc_url = "https://api.devnet.solana.com";
  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);
  ```

  ```ts web3.js
  import { Connection, clusterApiUrl } from "@solana/web3.js";

  const connection = new Connection(clusterApiUrl("devnet"), "confirmed");

  let leaderSchedule = await connection.getLeaderSchedule();

  console.log(leaderSchedule);
  ```

  ```rs 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://api.devnet.solana.com"),
          CommitmentConfig::confirmed(),
      );

      let slot_number = None;
      let config = RpcLeaderScheduleConfig {
          identity: String::from("dv1ZAGvdsz5hHLwWXsVnM94hWf1pjbKVau1QVkaMJ92").into(),
          commitment: CommitmentConfig::finalized().into(),
          ..Default::default()
      };
      let leader_schedule = client
          .get_leader_schedule_with_config(slot_number, config)
          .await?;

      println!("{:#?}", leader_schedule);

      Ok(())
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 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
  }
  ```
</ResponseExample>

## Parameters

<ParamField body="slot" type="u64 | object | null">
  Either the slot used to select the epoch, `null` to use the current slot at the
  requested commitment, or a configuration object.

  - If this parameter is a number, the RPC returns the leader schedule for the
    epoch that contains that slot.
  - If this parameter is `null` or omitted, the RPC uses the current epoch.
  - If this parameter is an object, it has the same shape as `config` and the
    request omits the slot.

  When this parameter is an object, it contains:

  | 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.                         |
  | `keyByVoteAccount` | `bool`   | Key the schedule by vote account instead of validator identity (Agave v4.4 and later). |
</ParamField>

<ParamField body="config" type="object">
  Configuration object containing the following fields. This parameter is only
  used when `slot` is a number or `null`.

  <Expandable title="properties" defaultOpen>
    <ParamField body="commitment" type="string" default="finalized">
      Values: `processed`, `confirmed`, `finalized`

      Solana RPC uses the following commitment levels:

      | Value       | Description                                                                                                                                                                               |
      | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `processed` | Return data from the highest slot this node has processed. This is the newest view, but the block can still be skipped.                                                                   |
      | `confirmed` | Return data from the same slot as `finalized`. Kept for compatibility and planned for removal in a later release.                                                                         |
      | `finalized` | Return data from the highest slot with a finalization certificate, from votes by 80% of stake in one round or 60% of stake in each of two rounds. This is the strongest commitment level. |
    </ParamField>

    <ParamField body="identity" type="string">
      Return only entries for this validator identity, as a base-58 encoded string.
      From Agave v4.4, an identity with no leader slots in the epoch returns error
      `-32022`; earlier versions return an empty object.
    </ParamField>

    <ParamField body="keyByVoteAccount" type="bool" default="false">
      Values: `true`, `false`

      When `true`, key the schedule by each leader's vote account instead of its
      validator identity. `identity` still filters by validator identity.

      <Warning>
        Available from Agave v4.4. Nodes running an earlier version ignore this
        field and key the schedule by validator identity.
      </Warning>

      ```json Example
      { "keyByVoteAccount": true }
      ```
    </ParamField>
  </Expandable>
</ParamField>

## Result

<ResponseField name="result" type="object | null">
  Returns `null` if the requested epoch is unavailable. Otherwise returns an
  object where:

  - Keys are validator identities, or vote accounts when `keyByVoteAccount` is
    `true` (as base-58 encoded strings)
  - Values are arrays of leader slot indices relative to the first slot in the
    requested epoch
</ResponseField>
