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

# Solana SPLトークンを取得する方法：完全なAPIガイド

> Heliusを使ってSolana SPLトークンデータを取得およびクエリする：残高、トークンアカウント、供給量、ホルダー、およびファンジブルトークン拡張機能を含む。コード例付き。

## 概要

このガイドは、Solanaでのファンジブルトークンの読み取りをカバーします： アカウントの残高、オーナーまたはミントによるトークンアカウント、総供給量、最大ホルダー、およびDASファンジブルトークン拡張。Heliusは標準のSolana RPCトークンメソッドと、メタデータやUSD価格を追加するDASメソッドの両方を公開しています。

NFT、圧縮NFT、エディション、証明については、[アセット取得ガイド](/ja/das/get-nfts)を参照してください。このページはファンジブル（SPLとToken-2022）トークンに焦点を当てています。

## これを使用するタイミング

このページの方法を使用するのは次のような場合です：

* 単一トークンアカウントの残高を読み取る場合
* ウォレットが保持するすべてのトークンアカウントをリストアップする場合
* 特定のミントを保持するすべてのアカウントを見つける場合
* トークンの総供給量または最大ホルダーを確認する場合
* 残高とともにトークンのメタデータとUSD価格を取得する場合

## トークンアカウント残高

標準RPCを使用して特定のトークンアカウントの残高を取得します：

```typescript theme={"system"}
const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: '1',
    method: 'getTokenAccountBalance',
    params: [
      '3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa'
    ]
  })
});
const data = await response.json();
console.log(data);
```

<Card title="APIリファレンス" horizontal icon="code" href="/ja/api-reference/rpc/http/gettokenaccountbalance">
  getTokenAccountBalance
</Card>

## 所有者別トークンアカウント

ウォレットによって所有されるすべてのトークンアカウントをリストします：

```typescript theme={"system"}
const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: '1',
    method: 'getTokenAccountsByOwner',
    params: [
      '86xCnPeV69n6t3DnyGvkKobf9FdN2H9oiVDdaMpo2MMY',
      {
        programId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
      },
      {
        encoding: 'jsonParsed'
      }
    ]
  })
});
const data = await response.json();
console.log(data);
```

<Card title="APIリファレンス" horizontal icon="code" href="/ja/api-reference/rpc/http/gettokenaccountsbyowner">
  getTokenAccountsByOwner
</Card>

## ミント別トークンアカウント

特定のトークンを保持するすべてのアカウントをリストします：

```typescript theme={"system"}
const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: '1',
    method: 'getTokenAccountsByOwner',
    params: [
      'CEXq1uy9y15PL2Wb4vDQwQfcJakBGjaAjeuR2nKLj8dk',
      {
        mint: "8wXtPeU6557ETkp9WHFY1n1EcU6NxDvbAggHGsMYiHsB"
      },
      {
        encoding: 'jsonParsed'
      }
    ]
  })
});
const data = await response.json();
console.log(data);
```

<Card title="APIリファレンス" horizontal icon="code" href="/ja/api-reference/rpc/http/gettokenaccountsbyowner">
  getTokenAccountsByOwner
</Card>

すべての所有者（単一の所有者に限定しない）にわたってミントを保持するすべてのアカウントを見つけるには、以下で説明するDAS `getTokenAccounts`メソッドを使用します。

## トークン供給

トークンの総供給量を確認します：

```typescript theme={"system"}
const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: '1',
    method: 'getTokenSupply',
    params: [
      'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
    ]
  })
});
const data = await response.json();
console.log(data);
```

<Card title="APIリファレンス" horizontal icon="code" href="/ja/api-reference/rpc/http/gettokensupply">
  getTokenSupply
</Card>

## 最大トークンホルダー

トークンを保持している最大のアカウントを特定します：

```typescript theme={"system"}
const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: '1',
    method: 'getTokenLargestAccounts',
    params: [
      'he1iusmfkpAdwvxLNGV8Y1iSbj4rUy6yMhEA3fotn9A'
    ]
  })
});
const data = await response.json();
console.log(data);
```

<Card title="APIリファレンス" horizontal icon="code" href="/ja/api-reference/rpc/http/gettokenlargestaccounts">
  getTokenLargestAccounts
</Card>

ミントに対して最大20のアカウントを返します：

```json theme={"system"}
{
  "context": { "slot": 0 },
  "value": [
    { "address": "...", "amount": "1000000000000", "decimals": 9, "uiAmount": 1000.0, "uiAmountString": "1000" }
  ]
}
```

## DAS APIによるトークンアカウント

DAS `getTokenAccounts`メソッドは、ミントまたは所有者によるトークンアカウントを、残高を含む単一のページネーションされた呼び出しで返します。`getTokenAccountsByOwner`とは異なり、ミントのすべての所有者にまたがるすべてのアカウントをリストするには`mint`のみでクエリ可能です。

```typescript theme={"system"}
const url = `https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY`;

const getTokenAccounts = async (params) => {
  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      jsonrpc: "2.0",
      id: "my-request-id",
      method: "getTokenAccounts",
      params: params,
    }),
  });

  const { result } = await response.json();
  return result;
};

// Example: Get all accounts holding a specific token
getTokenAccounts({
  mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
  page: 1,
  limit: 100
});
```

<Card title="APIリファレンス" horizontal icon="code" href="/ja/api-reference/das/gettokenaccounts">
  getTokenAccounts
</Card>

ページネーションされています；それぞれのエントリにはアカウント、ミント、所有者、残高が含まれます：

```json theme={"system"}
{
  "total": 100,
  "limit": 100,
  "page": 1,
  "token_accounts": [
    { "address": "...", "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "owner": "...", "amount": 12345678 }
  ]
}
```

## DAS APIによるトークンメタデータと価格

トークンメタデータとUSD価格を取得するには、`showFungible`を有効にしてDAS `getAsset`メソッドを呼び出します。検証済みトークンの価格は`token_info.price_info`で返されます。

<Note>
  `getAsset`からの価格データは最大600秒キャッシュされるため、最大10分前の情報です。
</Note>

```typescript theme={"system"}
const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: '1',
    method: 'getAsset',
    params: {
      id: 'DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263', // Bonk
      options: {
        showFungible: true
      }
    }
  })
});
const { result } = await response.json();
console.log(result.token_info.price_info);
```

<Card title="APIリファレンス" horizontal icon="code" href="/ja/api-reference/das/getasset">
  getAsset
</Card>

レスポンスには、`token_info`の下に供給、桁数、価格が返されます：

```json theme={"system"}
{
  "token_info": {
    "symbol": "Bonk",
    "supply": 8881594973561640000,
    "decimals": 5,
    "token_program": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
    "price_info": {
      "price_per_token": 0.0000192271,
      "currency": "USDC"
    }
  }
}
```

### 時価総額を計算

価格に10進数調整された供給を掛けます：

```typescript theme={"system"}
const { price_per_token } = result.token_info.price_info;
const { supply, decimals } = result.token_info;
const marketCap = (supply / Math.pow(10, decimals)) * price_per_token;
```

1回の呼び出しでウォレット内のすべてのファンジブルトークン（残高と価格を含む）をリストするには、`getAssetsByOwner`または`searchAssets`を`tokenType: "fungible"`と一緒に使用します。レスポンスで`tokenType`、残高、Token-2022拡張機能、価格データがどのように表示されるかについては[ファンジブルトークン拡張](/ja/das/fungible-token-extension)を参照してください。

## ベストプラクティス

* 大量の結果セットを返すメソッドに対してはページネーションを使用します。[ページネーションガイド](/ja/das/pagination)を参照してください。
* メタデータやUSD価格が必要な場合はDASメソッド（`getAsset`、`getAssetsByOwner`、`getTokenAccounts`）を優先します。生のオンチェーン残高や供給のためには標準RPCメソッドを使用します。
* エラーをtry/catchブロックとリトライで丁寧に処理します。
* 適切な場合はレスポンスをキャッシュし、APIコールを減らします。

## 次のステップ

<CardGroup cols={3}>
  <Card title="ファンジブルトークン拡張" icon="coins" href="/ja/das/fungible-token-extension">
    DASがファンジブルトークン、Token-2022拡張、価格を返す方法。
  </Card>

  <Card title="アセット取得（NFTs）" icon="image" href="/ja/das/get-nfts">
    NFTs、圧縮NFTs、エディション、証明を取得。
  </Card>

  <Card title="DAS APIリファレンス" icon="code" href="/ja/api-reference/das">
    すべてのDASメソッドの完全なスキーマ。
  </Card>
</CardGroup>
