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

# getTokenSupplyの使用方法

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

[`getTokenSupply`](https://www.helius.dev/docs/api-reference/rpc/http/gettokensupply) RPCメソッドは、特定のSPLトークンミントの総供給量を返します。これは、作成されたトークンの全体量を理解するために不可欠です。

## 一般的な使用例

* **トークン情報の表示:** エクスプローラやウォレットインターフェースでトークンの総供給量を表示します。
* **トークノミクス分析:** トークンの最大または現在の総発行量を理解します。
* **検証:** ミントアカウント自体が報告するトークン供給を確認します。
* **供給変動の監視:** トークンがミント可能な場合、その総供給の変化を追跡するのに使用できます（ただし、代替可能なトークンの場合、供給は通常固定されているか、発行権限によって管理されています）。

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

1. **`mintAddress`** (string, required): クエリしたいトークンミントのbase-58でエンコードされた公開鍵。

2. **`options`** (object, optional): オプションの設定オブジェクトには以下を含めることができます:
   * **`commitment`** (string, optional): クエリの[コミットメントレベル](https://www.helius.dev/blog/solana-commitment-levels)を指定します (例: `"finalized"`, `"confirmed"`, `"processed"`)。

## レスポンス構造

JSON-RPCレスポンスの`result.value`フィールドには、トークンの供給に関する詳細が含まれています。

* **`amount`** (string): トークンの最小単位（生データ量）での総供給。文字列として提供されます。この値は小数点には調整されていません。
* **`decimals`** (u8): このトークンミントで定義された小数点以下の桁数。これは、生データ量を人間が読みやすい形式に変換するのに重要です。
* **`uiAmount`** (number | null): トークンの`decimals`に合わせて調整された、浮動小数点数としてのトークンの総供給。このフィールドはnullまたは精度が低い場合があります。表示には通常、`uiAmountString`が推奨されます。
* **`uiAmountString`** (string): トークンの`decimals`に合わせて調整された文字列としてのトークンの総供給。これは総供給の最もユーザーフレンドリーな表現です。

**レスポンスの例:**

```json theme={"system"}
{
  "jsonrpc": "2.0",
  "result": {
    "context": { "slot": 123456789 },
    "value": {
      "amount": "1000000000000000", // e.g., 1,000,000,000 tokens with 6 decimals
      "decimals": 6,
      "uiAmount": 1000000000.0,
      "uiAmountString": "1000000000.0"
    }
  },
  "id": 1
}
```

## コード例

<CodeGroup>
  ```bash cURL theme={"system"}
  # Replace <TOKEN_MINT_PUBKEY> with the actual mint address
  curl -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getTokenSupply",
      "params": [
        "<TOKEN_MINT_PUBKEY>"
      ]
    }' \
    <YOUR_RPC_URL>

  # Example with commitment level
  curl -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getTokenSupply",
      "params": [
        "<TOKEN_MINT_PUBKEY>",
        { "commitment": "confirmed" }
      ]
    }' \
    <YOUR_RPC_URL>
  ```

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

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

    try {
      const tokenSupply = await connection.getTokenSupply(mintPublicKey);
      console.log(`Token Supply for Mint ${mintAddress}:`);
      console.log(`  UI Amount: ${tokenSupply.value.uiAmountString}`);
      console.log(`  Raw Amount: ${tokenSupply.value.amount}`);
      console.log(`  Decimals: ${tokenSupply.value.decimals}`);
      // For full details:
      // console.log(JSON.stringify(tokenSupply, null, 2));
    } catch (error) {
      console.error(`Error fetching token supply for mint ${mintAddress}:`, error);
    }
  }

  // Replace with the actual token mint public key you want to query
  const exampleTokenMint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'; // USDC mint
  checkTokenSupply(exampleTokenMint);

  // Example with a different mint (e.g., Raydium)
  // const raydiumMint = '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R';
  // checkTokenSupply(raydiumMint);
  ```
</CodeGroup>

## 開発者向けヒント

* **供給が不変（通常）:** ほとんどのSPLトークンでは、ミントアカウント自体の観点から見た総供給量は固定されており、特定の発行権限がある場合を除き、トークンを追加発行したり、（通常はトークンアカウントから）焼却することはできません。
* **`decimals`が重要:** `amount`または`uiAmountString`を正しく解釈するために、必ず`decimals`フィールドを使用してください。
* **データソース:** このメソッドはミントアカウントに直接クエリを実行し、供給情報を取得します。

このガイドは、Solana上でのSPLトークン供給のクエリにおいて、`getTokenSupply` RPCメソッドを効果的に使用するための必要な情報を提供します。
