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

# getSignatureStatusesの使用方法

> getSignatureStatusesの使用例、コード例、リクエストパラメータ、レスポンス構造、ヒントについて学ぶ。

この[`getSignatureStatuses`](https://www.helius.dev/docs/api-reference/rpc/http/getsignaturestatuses) RPCメソッドを使用すると、トランザクションシグネチャリストの処理および確認ステータスを取得できます。これは、トランザクションがネットワークによって[処理、確認、または最終化](https://www.helius.dev/blog/solana-commitment-levels)されたかどうかを確認するのに役立ちます。

`searchTransactionHistory`オプションが有効になっていない限り、このメソッドは主にRPCノードの最近のステータスキャッシュをクエリします。古いトランザクションの場合、`searchTransactionHistory`の有効化が重要です。

<Warning>
  **パフォーマンス向上のためバッチ処理は避ける**

  アーカイブメソッドのバッチ処理は遅延を大幅に増加させます。10リクエスト以上のバッチは許可されていません。
</Warning>

## 一般的な使用例

* **トランザクションの最終性の確認:** 提出されたトランザクションが希望する確認レベルに達したかどうかを確認する（例: `confirmed` または `finalized`）。
* **バッチステータスルックアップ:** バッチ送信後に複数のトランザクションのステータスを効率よく確認する。
* **トランザクション状態に基づくUIの更新:** トランザクションのリアルタイムステータスをユーザーに反映する。
* **エラーチェック:** トランザクションリストの中から失敗したものを特定し、その理由を判断する。

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

1. **`signatures`** (`array` of `string`): (必須) Base-58でエンコードされたトランザクションシグネチャの配列。1リクエストで最大256件のシグネチャをクエリできます。
2. **`options`** (`object`, 任意): 以下のフィールドを持つオプションの設定オブジェクト:
   * **`searchTransactionHistory`** (`boolean`, 任意): `true`の場合、RPCノードは完全なトランザクション履歴を検索します。`false`（デフォルト）の場合は、最近のステータスキャッシュのみを検索します。古い、またはドロップされた可能性のあるトランザクションには、これを`true`に設定します。

## レスポンス構造

JSON-RPCレスポンスの`result`フィールドには、2つのフィールドを持つオブジェクトが含まれています。

* **`context`** (`object`): 次を含むオブジェクト:
  * **`slot`** (`u64`): このリクエストをRPCノードが処理したスロット。
* **`value`** (`array` of `object` | `null`): リクエスト内のシグネチャの順序に対応するステータスオブジェクトの配列。各要素は以下の通りです。
  * シグネチャが見つかった場合の以下のフィールドを持つ**オブジェクト**:
    * **`slot`** (`u64`): トランザクションが処理されたスロット。
    * **`confirmations`** (`number` | `null`): トランザクションが処理された後に確認されたブロックの数。トランザクションが最終化された場合は`null`（最終化はロールバックされないので特定の確認数は重要ではありません）。
    * **`err`** (`object` | `null`): トランザクションが失敗した場合のエラーオブジェクト（例: `{"InstructionError":[0,{"Custom":1}]}`）、成功した場合は`null`。
    * **`status`** (`object`): トランザクションの実行ステータスを示すオブジェクト。通常、成功したトランザクションの場合は`{"Ok":null}`、失敗した場合はエラーを詳細に示すオブジェクト。
    * **`confirmationStatus`** (`string` | `null`): トランザクションに対するクラスタの確認ステータス（例: `processed`, `confirmed`, `finalized`）。キャッシュでステータスが利用できず、`searchTransactionHistory`がfalseの場合は`null`になることがあります。
  * **`null`**: シグネチャがステータスキャッシュで見つからず、`searchTransactionHistory`が`false`の場合（または履歴検索でも実際に存在しない場合）。

## 例

### 1. 複数のシグネチャのステータスを取得（最近のキャッシュから）

この例では、ノードの最近のキャッシュに依存して、2つのシグネチャのステータスを取得します。

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  # Replace with actual transaction signatures
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getSignatureStatuses",
      "params": [
        [
          "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW",
          "2x5YfV29N4p9K2kEFK2gFfC5T5acbs2z2MytTZqrgq17pYjCMfYjW4sAUpkWMkMzxGztD2Qv5v7n92uYJcQY9c7a" 
        ]
      ]
    }'
  ```

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

  async function checkRecentSignatures() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    const signatures = [
      '5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW',
      '2x5YfV29N4p9K2kEFK2gFfC5T5acbs2z2MytTZqrgq17pYjCMfYjW4sAUpkWMkMzxGztD2Qv5v7n92uYJcQY9c7a' // Replace with another signature
    ];

    try {
      const response = await connection.getSignatureStatuses(signatures);
      console.log("RPC Response Context Slot:", response.context.slot);
      response.value.forEach((status, index) => {
        console.log(`--- Status for Signature ${index + 1} (${signatures[index].substring(0,10)}...) ---`);
        if (status) {
          console.log(`  Slot: ${status.slot}`);
          console.log(`  Confirmations: ${status.confirmations === null ? 'Finalized (or N/A)' : status.confirmations}`);
          console.log(`  Error: ${JSON.stringify(status.err)}`);
          console.log(`  Execution Status: ${JSON.stringify(status.status)}`);
          console.log(`  Confirmation Status: ${status.confirmationStatus}`);
        } else {
          console.log('  Status not found (likely not in recent cache or does not exist).');
        }
      });
    } catch (error) {
      console.error('Error fetching signature statuses:', error);
    }
  }

  checkRecentSignatures();
  ```
</CodeGroup>

### 2. トランザクション履歴検索によるステータス取得

この例では、シグネチャのステータスを取得し、ノードにトランザクション履歴の検索を明示的に要求します。

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <api-key> with your Helius API key
  # Replace with actual transaction signatures
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getSignatureStatuses",
      "params": [
        [
          "3jPTfHcbzWHeD4jW8q4Y8g3h2D1aBwM81y1sHhDqYQ7Z9x5n7cVy2gD8QWbK9eXwSjJ6aA7FzV2kLpQoEwU9jX", 
          "4SyzjM2fTALqTNjLKMM1yG1bW7kCFu2GvEkKcvKChG9o1KjQW8jLdZ6sWfN9mP1pU3rD7XvA6B2CjHkLwRzYxTnX"  
        ],
        {
          "searchTransactionHistory": true
        }
      ]
    }'
  ```

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

  async function checkSignaturesWithHistory() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    const signatures = [
      // Replace with a signature you know is older or might have been dropped
      '3jPTfHcbzWHeD4jW8q4Y8g3h2D1aBwM81y1sHhDqYQ7Z9x5n7cVy2gD8QWbK9eXwSjJ6aA7FzV2kLpQoEwU9jX',
      // Replace with another valid signature
      '4SyzjM2fTALqTNjLKMM1yG1bW7kCFu2GvEkKcvKChG9o1KjQW8jLdZ6sWfN9mP1pU3rD7XvA6B2CjHkLwRzYxTnX' 
    ];

    try {
      const response = await connection.getSignatureStatuses(signatures, { searchTransactionHistory: true });
      console.log("RPC Response Context Slot:", response.context.slot);
      response.value.forEach((status, index) => {
        console.log(`--- Status for Signature ${index + 1} (${signatures[index].substring(0,10)}...) ---`);
        if (status) {
          console.log(`  Slot: ${status.slot}`);
          console.log(`  Confirmations: ${status.confirmations === null ? 'Finalized (or N/A)' : status.confirmations}`);
          console.log(`  Error: ${JSON.stringify(status.err)}`);
          console.log(`  Execution Status: ${JSON.stringify(status.status)}`);
          console.log(`  Confirmation Status: ${status.confirmationStatus}`);
        } else {
          console.log('  Status not found (even with history search, it might not exist or is too old).');
        }
      });
    } catch (error) {
      console.error('Error fetching signature statuses with history:', error);
    }
  }

  checkSignaturesWithHistory();
  ```
</CodeGroup>

## 開発者向けヒント

* **`searchTransactionHistory`:** 信頼性のために重要です。`false`（デフォルト）の場合、メソッドは限定された最近のキャッシュのみをチェックします。トランザクションが古い、またはこのキャッシュにない可能性がある場合、そのシグネチャのステータスに対して`null`が返されます。非常に新しくないトランザクションのステータスを確認する必要がある場合は、常に`true`に設定してください。
* **シグネチャ制限:** 1回の呼び出しで最大256件のシグネチャをクエリできます。
* **`null` ステータス:** 特定のシグネチャに対して`value`配列内の`null`は、そのステータスが見つからなかったことを意味します。これは、最近のキャッシュにない（`searchTransactionHistory`がfalseの場合）、トランザクションが着地していない、または`searchTransactionHistory: true`でも古すぎてノードの履歴にないためかもしれません。
* **`confirmations: null`**: 通常、このトランザクションが`finalized` ステータスに到達したことを意味します。この段階では、ブロックは不可逆と見なされるため、特定の確認数の概念はあまり関係ありません。
* **エラーハンドリング:** トランザクションが失敗したかどうかを確認するには、各ステータスオブジェクト内の`err`フィールドをチェックします。`status`フィールドも詳細を提供します（例: `{"Err":...}`）。

`getSignatureStatuses`を使用することは、複数のSolanaトランザクションの状態を監視する効率的な方法です。堅牢なステータスチェックのために`searchTransactionHistory: true`を使用することを忘れないでください。
