> ## 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.

# getVoteAccountsの使用方法

> getVoteAccountsの使用例、コード例、リクエストパラメータ、レスポンス構造、およびヒントを学びます。

この[`getVoteAccounts`](https://www.helius.dev/docs/api-reference/rpc/http/getvoteaccounts) RPCメソッドは、現在のバンク内のすべての投票アカウント（バリデーター）に関する情報を返します。`current`（アクティブ）バリデーターと`delinquent`バリデーターを区別し、ステーク、投票活動、アイデンティティに関する詳細を提供します。

## 一般的なユースケース

* **バリデーターモニタリング:** ネットワーク上のバリデーターのステータス、ステーク、およびパフォーマンスを追跡します。
* **ステーキングダッシュボード:** SOLを委任しようとしているユーザー向けに利用可能なバリデーターの情報を表示します。
* **ネットワークの健全性分析:** ステークの分布とバリデーターの活動を調査することで、ネットワーク全体の健全性と分散性を評価します。
* **怠惰なバリデーターの特定:** コンセンサスに積極的に参加していないバリデーターを見つけます。

## リクエストパラメータ

このメソッドは、以下のフィールドを持つオプションの設定オブジェクトを受け入れます。

1. **`commitment`** (string, optional): クエリの[コミットメントレベル](https://www.helius.dev/blog/solana-commitment-levels) を指定します（例：`"finalized"`, `"confirmed"`, `"processed"`）。省略した場合、ノードのデフォルトのコミットメントが使用されます。
2. **`votePubkey`** (string, optional): 提供された場合、指定されたバリデーターの投票アカウントアドレス（base-58エンコード）のみを含むように結果がフィルタリングされます。
3. **`keepUnstakedDelinquents`** (boolean, optional): デフォルトは`false`です。`true`に設定すると、ステークがアクティブでないバリデーターも含まれます。それ以外の場合はフィルタリングされます。
4. **`delinquentSlotDistance`** (u64, optional): 台帳の先端から遅れているスロット数を指定して、怠惰と見なされるバリデーターを決定します。指定しない場合、ノードのデフォルト値が使用されます。

## レスポンス構造

JSON-RPCレスポンスの`result`フィールドは、2つの配列を含むオブジェクトです。

* **`current`**: オブジェクトの配列であり、各オブジェクトは次のフィールドを持つアクティブな投票アカウントを表します。
  * **`votePubkey`** (string): 投票アカウントアドレス（base-58エンコード）。
  * **`nodePubkey`** (string): バリデーターノードのアイデンティティ公開鍵（base-58エンコード）。
  * **`activatedStake`** (u64): この投票アカウントに委任され、現在のエポックでアクティブなステーク量（lamports）。
  * **`epochVoteAccount`** (boolean): 現在のエポック中に少なくとも一度アクティブだった場合に`true`。
  * **`commission`** (number): バリデーターによって課せられる手数料の割合（0-100）。
  * **`lastVote`** (u64): 最も最近バリデーターが投票したスロット番号。
  * **`rootSlot`** (u64): ノードがルートと見なした最後のスロット（完全に確認されてロールバックされることのないブロック）。
  * **`epochCredits`** (array): 各内部配列が`[epoch, credits_earned_in_epoch, previous_total_credits]`を含む配列の配列。
* **`delinquent`**: ノードによって怠惰と見なされるバリデーターを表す、`current`と同様の構造を持つオブジェクトの配列。

**レスポンス例のスニペット:**

```json theme={"system"}
{
  "jsonrpc": "2.0",
  "result": {
    "current": [
      {
        "commission": 10,
        "epochCredits": [[300, 12345, 567890]],
        "epochVoteAccount": true,
        "lastVote": 180000500,
        "nodePubkey": "NodePubkeyExample123...",
        "rootSlot": 180000450,
        "activatedStake": "50000000000000", // lamports
        "votePubkey": "VoteAccountPubkeyExample123..."
      }
      // ... more current validators
    ],
    "delinquent": [
      // ... delinquent validators, if any
    ]
  },
  "id": 1
}
```

## コード例

<CodeGroup>
  ```bash cURL theme={"system"}
  # Get all current and delinquent vote accounts:
  curl -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getVoteAccounts"
    }' \
    <YOUR_RPC_URL>

  # Get a specific vote account:
  curl -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getVoteAccounts",
      "params": [
        {
          "votePubkey": "<SPECIFIC_VOTE_ACCOUNT_PUBKEY>"
        }
      ]
    }' \
    <YOUR_RPC_URL>

  # Get vote accounts with "confirmed" commitment and keep unstaked delinquents:
  curl -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getVoteAccounts",
      "params": [
        {
          "commitment": "confirmed",
          "keepUnstakedDelinquents": true
        }
      ]
    }' \
    <YOUR_RPC_URL>
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  const { Connection } = require('@solana/web3.js');

  async function fetchVoteAccounts() {
    // Replace with your RPC endpoint
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');

    try {
      // Get all vote accounts
      const voteAccounts = await connection.getVoteAccounts();
      console.log(`Found ${voteAccounts.current.length} current validators.`);
      console.log(`Found ${voteAccounts.delinquent.length} delinquent validators.`);

      if (voteAccounts.current.length > 0) {
        console.log("\nFirst current validator details:");
        console.log(`  Vote Pubkey: ${voteAccounts.current[0].votePubkey}`);
        console.log(`  Node Pubkey: ${voteAccounts.current[0].nodePubkey}`);
        console.log(`  Activated Stake: ${voteAccounts.current[0].activatedStake} lamports`);
        console.log(`  Commission: ${voteAccounts.current[0].commission}%`);
        console.log(`  Last Vote: ${voteAccounts.current[0].lastVote}`);
        // console.log(JSON.stringify(voteAccounts.current[0], null, 2)); // For full details
      }

      // Get a specific vote account (replace with an actual vote account public key)
      // const specificVotePubkey = 'SPECIFIC_VOTE_ACCOUNT_PUBKEY';
      // const specificValidator = await connection.getVoteAccounts('confirmed', specificVotePubkey);
      // console.log(`\nDetails for ${specificVotePubkey}:`, JSON.stringify(specificValidator, null, 2));

    } catch (error) {
      console.error('Error fetching vote accounts:', error);
    }
  }

  fetchVoteAccounts();
  ```
</CodeGroup>

## 開発者へのヒント

* **大きなレスポンス:** このメソッドは、多くのバリデーターがあるネットワーク（例えばMainnet Beta）で大量のデータを返すことがあります。レスポンスサイズと処理時間に注意してください。
* **怠惰の定義:** 「怠惰」の定義は、`delinquentSlotDistance`とノードの視点に依存します。あるノードでは怠惰に見えるバリデーターが、別のノードではそう見えないかもしれません。台帳の先端への見解が異なるためです。
* **ステークのアクティベーション:** `activatedStake`は、現在のエポックでアクティブなステークを反映しています。ステークのアクティベーションとデアクティベーションには時間がかかります。
* **エポッククレジット:** `epochCredits`は、投票によってクレジットを獲得するバリデーターのパフォーマンス履歴を提供します。

このガイドは、Solanaネットワーク上でバリデーター情報をクエリし、理解するための`getVoteAccounts` RPCメソッドをカバーしています。
