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

# requestAirdropの使用方法

> requestAirdropの使用ケース、コード例、リクエストパラメータ、応答構造、ヒントを学びます。

[`requestAirdrop`](https://www.helius.dev/docs/api-reference/rpc/http/requestairdrop) RPCメソッドは、指定されたアカウントにSOL（lamports）のエアドロップをリクエストすることができます。このメソッドは**DevnetやTestnetのような非メインネット環境専用**であり、開発者に無料のSOLを提供するためのファーセットとして機能します。

**重要: このメソッドはMainnet Betaでは動作しません。**

## 一般的な使用ケース

* **テストウォレットへの資金供給:** DevnetまたはTestnetでのトランザクション手数料の支払いとプログラムのデプロイのためにSOLを取得します。
* **自動化テスト:** スクリプトはテストアカウントに十分なSOLがあることを確認するために`requestAirdrop`を使用できます。
* **開発と実験:** 開発中にオンチェーンプログラムと対話するために素早くSOLを取得します。

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

1. **`pubkey`** (文字列, 必須): エアドロップされるlamportsを受け取るアカウントの公開鍵で、base-58エンコードされた文字列として提供されます。
2. **`lamports`** (u64, 必須): リクエストするlamportsの量。（1 SOL = 1,000,000,000 lamports）
3. **`options`** (オブジェクト, 任意): オプションの構成オブジェクトで、以下を含むことができます:
   * **`commitment`** (文字列, 任意): エアドロップトランザクションを確認する際の[コミットメントレベル](https://www.helius.dev/blog/solana-commitment-levels)を指定します（例: `"finalized"`, `"confirmed"`, `"processed"`）。省略した場合、ノードのデフォルトのコミットメントが使用されます。

## 応答構造

JSON-RPCの応答内の`result`フィールドは、エアドロップのトランザクション署名を表す単一の文字列であり、base-58でエンコードされています。

**応答例:**

```json theme={"system"}
{
  "jsonrpc": "2.0",
  "result": "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW",
  "id": 1
}
```

この署名は、その後`getTransaction`やSolanaエクスプローラーを使用してエアドロップトランザクションの状況を追跡するために使用できます。

## コード例

<CodeGroup>
  ```bash cURL theme={"system"}
  # Request 1 SOL (1,000,000,000 lamports) to a Devnet address
  # Replace <YOUR_WALLET_ADDRESS> with an actual base-58 public key
  # Ensure you are targeting a Devnet RPC URL
  curl -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "requestAirdrop",
      "params": [
        "<YOUR_WALLET_ADDRESS>",
        1000000000
      ]
    }' \
    https://devnet.helius-rpc.com/?api-key=<api-key> 

  # Request 0.5 SOL with "confirmed" commitment
  curl -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "requestAirdrop",
      "params": [
        "<YOUR_WALLET_ADDRESS>",
        500000000,
        {
          "commitment": "confirmed"
        }
      ]
    }' \
    https://devnet.helius-rpc.com/?api-key=<api-key>
  ```

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

  async function getAirdrop(walletAddress) {
    // Connect to Devnet
    const connection = new Connection('https://devnet.helius-rpc.com/?api-key=<api-key>', 'confirmed');
    const publicKey = new PublicKey(walletAddress);

    try {
      console.log(`Requesting airdrop of 1 SOL to ${walletAddress} on Devnet...`);
      
      // Request an airdrop of 1 SOL
      const airdropSignature = await connection.requestAirdrop(
        publicKey,
        LAMPORTS_PER_SOL // 1 SOL
      );

      console.log(`Airdrop requested. Transaction signature: ${airdropSignature}`);

      // Confirm the transaction
      // Note: The `confirmTransaction` method in web3.js has evolved.
      // For newer versions, you might use `connection.confirmTransaction({ signature: airdropSignature, blockhash: latestBlockhash.blockhash, lastValidBlockHeight: latestBlockhash.lastValidBlockHeight }, 'confirmed');`
      // For simplicity, we'll log the signature and you can check on an explorer.
      // Or, more robustly, you can poll getSignatureStatuses.

      await connection.confirmTransaction(airdropSignature);
      console.log(`Airdrop successful for ${walletAddress}!`);

      const balance = await connection.getBalance(publicKey);
      console.log(`Current balance for ${walletAddress}: ${balance / LAMPORTS_PER_SOL} SOL`);

    } catch (error) {
      console.error(`Error requesting airdrop for ${walletAddress}:`, error);
    }
  }

  // Replace with a Devnet wallet address you control
  const myDevnetWallet = 'REPLACE_WITH_YOUR_DEVNET_WALLET_ADDRESS'; 
  // Example: const myDevnetWallet = new Keypair().publicKey.toBase58(); // For a new temporary wallet

  if (myDevnetWallet === 'REPLACE_WITH_YOUR_DEVNET_WALLET_ADDRESS') {
    console.warn("Please replace 'REPLACE_WITH_YOUR_DEVNET_WALLET_ADDRESS' with an actual Devnet wallet address to run the example.");
  } else {
    // getAirdrop(myDevnetWallet);
    console.log("Uncomment the line above and replace the placeholder to run the airdrop example.");
  }
  ```
</CodeGroup>

## 開発者ヒント

* **ネットワーク特有:** このメソッドは、ファーセットが有効なテストネットワーク（Devnet、Testnet）でのみ機能します。Mainnet Betaでは失敗します。
* **レート制限:** エアドロップファーセットは悪用を防ぐためにレート制限されることがよくあります。短期間に多くのリクエストを行うと、エラーが返される可能性があります。
* **量制限:** エアドロップごと、または時間枠ごとにリクエストできるSOLの量に制限がある場合があります。
* **確認:** `requestAirdrop`が署名を返した後、トランザクションはネットワークによって処理および確認される必要があります。確認待ちには`confirmTransaction`（`@solana/web3.js`から）を使用するか、`getSignatureStatuses`をポーリングすることができます。

このガイドは、Solanaの開発ネットワークでテストアカウントに資金を供給するために`requestAirdrop`を使用する方法を説明しています。

## 関連メソッド

<CardGroup cols={2}>
  <Card title="getBalance" href="/ja/api-reference/rpc/http/getbalance">
    エアドロップを受け取った後のSOL残高を確認
  </Card>

  <Card title="getSignatureStatuses" href="/ja/api-reference/rpc/http/getsignaturestatuses">
    エアドロップ確認のためにトランザクションのステータスをポーリング
  </Card>
</CardGroup>
