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

# Cara Menggunakan getLeaderSchedule

> Pelajari kasus penggunaan getLeaderSchedule, contoh kode, parameter permintaan, struktur respons, dan tips.

Metode RPC [`getLeaderSchedule`](https://www.helius.dev/docs/api-reference/rpc/http/getleaderschedule) menampilkan penetapan kepemimpinan produksi blok kepada validator untuk epoch tertentu. Memahami jadwal pemimpin dapat berguna untuk analisis jaringan, memprediksi validator yang akan menghasilkan blok pada waktu tertentu, atau untuk alat yang berinteraksi dengan pemimpin tertentu.

## Kasus Penggunaan Umum

* **Pemantauan Jaringan:** Amati distribusi slot pemimpin di antara validator dalam sebuah epoch.
* **Perutean Transaksi (Lanjutan):** Beberapa aplikasi lanjutan mungkin mencoba merutekan transaksi ke pemimpin saat ini atau berikutnya, meskipun hal ini umumnya ditangani oleh jaringan dan node RPC.
* **Analisis Kinerja Validator:** Korelasikan jadwal pemimpin dengan produksi blok aktual untuk menilai waktu aktif dan kinerja validator.
* **Memahami Perkembangan Epoch:** Lihat validator yang bertanggung jawab menghasilkan blok sepanjang epoch.

## Parameter Permintaan

Metode ini dapat menerima hingga dua parameter opsional:

1. **`slot`** (u64, opsional): Nomor slot. Jika diberikan, jadwal pemimpin untuk epoch yang berisi slot ini akan diambil. Jika `null` atau dihilangkan, jadwal pemimpin untuk epoch saat ini akan diambil.
2. **`config`** (objek, opsional): Objek konfigurasi yang dapat berisi:
   * **`commitment`** (string, opsional): Menentukan [tingkat komitmen](https://www.helius.dev/blog/solana-commitment-levels). Jika tidak diberikan, komitmen default node akan digunakan.
   * **`identity`** (string, opsional): Kunci publik validator yang dikodekan dalam base-58. Jika diberikan, jadwal yang ditampilkan hanya akan mencakup slot yang ditetapkan kepada validator khusus ini.

## Struktur Respons

Kolom `result` pada respons JSON-RPC akan berupa:

* `null`: Jika epoch yang sesuai dengan `slot` yang diminta (atau epoch saat ini jika slot tidak diberikan) tidak ditemukan atau jadwal pemimpinnya tidak tersedia (misalnya, untuk epoch mendatang yang belum dihitung).
* Sebuah **objek**: Jika jadwal ditemukan. Objek ini adalah peta dengan ketentuan berikut:
  * Setiap **kunci** adalah kunci publik (identitas) validator yang dikodekan dalam base-58.
  * **Nilai** yang sesuai adalah larik angka. Setiap angka merupakan indeks slot *relatif terhadap awal epoch* saat validator tersebut menjadi pemimpin.

Sebagai contoh, jika sebuah epoch dimulai pada slot `1000` dan validator memiliki `[0, 1, 5]` dalam jadwalnya, berarti validator tersebut menjadi pemimpin untuk slot `1000`, `1001`, dan `1005`.

## Contoh

### 1. Mendapatkan Jadwal Pemimpin untuk Epoch Saat Ini

Contoh ini mengambil jadwal pemimpin lengkap untuk epoch saat ini.

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getLeaderSchedule"
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  const { Connection } = require('@solana/web3.js');

  async function fetchCurrentLeaderSchedule() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    try {
      const leaderSchedule = await connection.getLeaderSchedule(); // Fetches for current epoch by default
      if (leaderSchedule) {
        console.log('Leader Schedule for Current Epoch:');
        for (const [validatorIdentity, slots] of Object.entries(leaderSchedule)) {
          console.log(`  Validator: ${validatorIdentity}`);
          console.log(`    Slots (relative to epoch start): ${slots.join(', ')}`);
        }
      } else {
        console.log('Leader schedule for the current epoch not found or not yet available.');
      }
      // console.log(JSON.stringify(leaderSchedule, null, 2));
    } catch (error) {
      console.error('Error fetching leader schedule:', error);
    }
  }

  fetchCurrentLeaderSchedule();
  ```
</CodeGroup>

### 2. Mendapatkan Jadwal Pemimpin untuk Validator Tertentu dalam Epoch Tertentu (berdasarkan Slot)

Contoh ini mengambil jadwal pemimpin untuk identitas validator tertentu dalam epoch yang berisi slot `200000`.

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  # Replace VALIDATOR_PUBKEY with an actual validator identity public key
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getLeaderSchedule",
      "params": [
        200000,
        { "identity": "VALIDATOR_PUBKEY" }
      ]
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  // Replace VALIDATOR_PUBKEY with an actual validator identity public key
  const { Connection, PublicKey } = require('@solana/web3.js');

  async function fetchValidatorEpochSchedule() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    const targetSlot = 200000;
    const validatorIdentity = 'VALIDATOR_PUBKEY'; // e.g., 'Vote111111111111111111111111111111111111111'

    try {
      const leaderSchedule = await connection.getLeaderSchedule(targetSlot, { identity: validatorIdentity });
      if (leaderSchedule && leaderSchedule[validatorIdentity]) {
        console.log(`Leader Schedule for Validator ${validatorIdentity} in epoch of slot ${targetSlot}:`);
        console.log(`  Slots (relative to epoch start): ${leaderSchedule[validatorIdentity].join(', ')}`);
      } else {
        console.log(`No leader slots found for validator ${validatorIdentity} in epoch of slot ${targetSlot}, or schedule not available.`);
      }
      // console.log(JSON.stringify(leaderSchedule, null, 2));
    } catch (error) {
      console.error('Error fetching validator leader schedule:', error);
    }
  }

  fetchValidatorEpochSchedule();
  ```
</CodeGroup>

## Tips untuk Developer

* **Batas Epoch:** Jadwal pemimpin tetap untuk seluruh epoch. Anda dapat menggunakan `getEpochInfo` untuk menemukan slot awal dan akhir suatu epoch.
* **Epoch Mendatang:** Meminta jadwal untuk epoch yang masih jauh di masa mendatang mungkin menampilkan `null` jika jaringan belum menghitungnya.
* **Indeks Slot Relatif:** Ingat bahwa nomor slot dalam respons bersifat relatif terhadap slot pertama dari epoch yang *diminta*, bukan nomor slot absolut pada blockchain.
* **Respons Besar:** Untuk jadwal epoch lengkap tanpa filter identitas, respons dapat berukuran besar dan mencantumkan semua validator beserta slot yang ditetapkan kepada mereka.

Panduan ini menyediakan informasi yang diperlukan untuk menggunakan `getLeaderSchedule` guna meminta informasi penetapan produsen blok untuk epoch tertentu di jaringan Solana.

## Metode Terkait

<CardGroup cols={2}>
  <Card title="getEpochInfo" href="/docs/id/api-reference/rpc/http/getepochinfo">
    Dapatkan informasi epoch saat ini, termasuk batas slot
  </Card>

  <Card title="getSlotLeaders" href="/docs/id/api-reference/rpc/http/getslotleaders">
    Dapatkan pemimpin untuk rentang slot tertentu
  </Card>
</CardGroup>
