> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chainstream.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 初めてのクエリ

> IDE と cURL から初めての GraphQL クエリをステップバイステップで実行

<Note>
  **目安時間**: 5 分
</Note>

## 前提条件

始める前に、次を用意してください。

* ChainStream の登録アカウント（[こちらから登録](https://www.chainstream.io/dashboard)）
* API Key（`cs_live_...` で始まる）

<Tip>
  GraphQL API は REST Data API と同じ API Key を使います。REST API で既にキーをお持ちの場合、ここでもそのまま利用できます。
</Tip>

***

## ステップ 1: API Key を取得する

1. [ChainStream Dashboard](https://www.chainstream.io/dashboard) にログイン
2. **Applications** を開く
3. **Create New App** をクリック（または既存のアプリを選択）
4. **API Key** をコピー

***

## ステップ 2: GraphQL IDE を開く

ChainStream GraphQL IDE にアクセスします。

<Card title="GraphQL IDE" icon="code" href="https://ide.chainstream.io">
  [https://ide.chainstream.io](https://ide.chainstream.io)
</Card>

IDE ではオートコンプリート、シンタックスハイライト、インラインドキュメント、クエリ履歴が利用でき、スキーマの探索とクエリ構築が最も速く行えます。

***

## ステップ 3: 認証を設定する

IDE で **Headers** パネル（左下）を開き、API Key を追加します。

```json theme={null}
{
  "X-API-KEY": "your_api_key"
}
```

***

## ステップ 4: サンプルクエリを実行する

次のクエリをエディタに貼り付けます。**Solana 上の最新 10 件の DEX 取引**を取得し、ブロック時刻、トランザクションハッシュ、買い/売りトークン情報、数量、USD 価格、DEX プロトコル名を含みます。

```graphql theme={null}
query {
  Solana {
    DEXTrades(
      limit: {count: 10}
      orderBy: {descending: Block_Time}
    ) {
      Block {
        Time
        Slot
      }
      Transaction {
        Hash
      }
      Trade {
        Buy {
          Currency { MintAddress }
          Amount
          PriceInUSD
        }
        Sell {
          Currency { MintAddress }
          Amount
        }
        Dex { ProtocolName }
      }
    }
  }
}
```

<Tip>
  [GraphQL IDE で開く](https://ide.chainstream.io) — 上記クエリを貼り付けて、オートコンプリートとスキーマ探索付きで対話的に実行できます。
</Tip>

**Play** ボタンをクリックするか、`Ctrl+Enter` / `Cmd+Enter` で実行します。

***

## cURL での同等の呼び出し

ターミナルから同じクエリを実行できます。

```bash theme={null}
curl -X POST "https://graphql.chainstream.io/graphql" \
  -H "Content-Type: application/json" \
  -H "X-API-KEY: your_api_key" \
  -d '{
    "query": "{ Solana { DEXTrades(limit: {count: 10}, orderBy: {descending: Block_Time}) { Block { Time Slot } Transaction { Hash } Trade { Buy { Currency { MintAddress } Amount PriceInUSD } Sell { Currency { MintAddress } Amount } Dex { ProtocolName } } } } }"
  }'
```

***

## レスポンス例

成功時のレスポンスの例です。

```json theme={null}
{
  "data": {
    "Solana": {
      "DEXTrades": [
        {
          "Block": {
            "Time": "2025-03-27T10:32:18Z",
            "Slot": 325847291
          },
          "Transaction": {
            "Hash": "4vKzR8g...x9bQ"
          },
          "Trade": {
            "Buy": {
              "Currency": { "MintAddress": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" },
              "Amount": 1523.45,
              "PriceInUSD": 1.0001
            },
            "Sell": {
              "Currency": { "MintAddress": "So11111111111111111111111111111111111111112" },
              "Amount": 10.237
            },
            "Dex": { "ProtocolName": "Raydium" }
          }
        },
        {
          "Block": {
            "Time": "2025-03-27T10:32:17Z",
            "Slot": 325847289
          },
          "Transaction": {
            "Hash": "3mPqW7n...kR2J"
          },
          "Trade": {
            "Buy": {
              "Currency": { "MintAddress": "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263" },
              "Amount": 48291037.12,
              "PriceInUSD": 0.00003152
            },
            "Sell": {
              "Currency": { "MintAddress": "So11111111111111111111111111111111111111112" },
              "Amount": 10.5
            },
            "Dex": { "ProtocolName": "Orca" }
          }
        }
      ]
    }
  },
  "extensions": {
    "credits": {
      "total": 50,
      "cubes": [
        { "cube": "DEXTrades", "credits": 50, "row_count": 10 }
      ]
    }
  }
}
```

***

## レスポンスの読み方

レスポンスはクエリの構造と対応します。

| パス                                | 説明                                             |
| :-------------------------------- | :--------------------------------------------- |
| `Block.Time`                      | ISO 8601 形式のブロックタイムスタンプ                        |
| `Block.Slot`                      | Solana のスロット番号（Solana 固有）                      |
| `Transaction.Hash`                | オンチェーンのトランザクションハッシュ                            |
| `Trade.Buy.Currency.MintAddress`  | 買い側トークンのアドレス                                   |
| `Trade.Buy.Amount`                | 買い側トークンの数量                                     |
| `Trade.Buy.PriceInUSD`            | 取引時点での買い側トークンの USD 価格                          |
| `Trade.Sell.Currency.MintAddress` | 売り側トークンのアドレス                                   |
| `Trade.Sell.Amount`               | 売り側トークンの数量                                     |
| `Trade.Dex.ProtocolName`          | 取引を実行した DEX プロトコル（例: Raydium、Orca、PancakeSwap） |

<Info>
  `extensions.credits` オブジェクトは、このクエリで消費した課金クレジット数と残高を示します。詳しくは [Billing & Credits](/jp/graphql/billing/graphql-billing) を参照してください。
</Info>

***

## クエリを変えてみる

動作するクエリが得られたら、次の変更を試してください。

<AccordionGroup>
  <Accordion title="Ethereum に切り替える">
    `Solana` の代わりに `EVM(network: eth) { ... }` を使い、Ethereum の DEX 取引（Uniswap、SushiSwap など）を問い合わせます。
  </Accordion>

  <Accordion title="時間フィルタを追加する">
    `where` 句を追加して直近 1 時間の取引に絞ります。

    ```graphql theme={null}
    Solana {
      DEXTrades(
        limit: {count: 10}
        orderBy: {descending: Block_Time}
        where: {Block: {Time: {after: "2025-03-27T09:00:00Z"}}}
      ) { ... }
    }
    ```
  </Accordion>

  <Accordion title="特定のトークンを問い合わせる">
    トークンの mint アドレスで絞り、特定トークンの取引だけを見ます。

    ```graphql theme={null}
    Solana {
      DEXTrades(
        limit: {count: 10}
        orderBy: {descending: Block_Time}
        where: {Trade: {Buy: {Currency: {MintAddress: {is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}}}}
      ) { ... }
    }
    ```
  </Accordion>

  <Accordion title="集約を追加する">
    DEX プロトコルごとの取引総数を数えます。

    ```graphql theme={null}
    Solana {
      DEXTrades(
        where: {Block: {Time: {after: "2025-03-27T00:00:00Z"}}}
      ) {
        count
        Trade { Dex { ProtocolName } }
      }
    }
    ```
  </Accordion>
</AccordionGroup>

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="スキーマとデータモデル" icon="diagram-project" href="/jp/graphql/schema/schema-overview">
    25 の Cube、フィールド型、フィルタ演算子、集約関数を確認。
  </Card>

  <Card title="クエリ例" icon="flask" href="/jp/graphql/examples/dex-trades">
    DEX 取引、転送、OHLC、ホルダーなどの実践的なクエリ例を参照。
  </Card>

  <Card title="GraphQL IDE ガイド" icon="code" href="/jp/graphql/ide/introduction">
    IDE の使い方 — クエリテンプレート、保存クエリ、Variables パネル、コードエクスポート。
  </Card>

  <Card title="課金とクレジット" icon="credit-card" href="/jp/graphql/billing/graphql-billing">
    クエリクレジットの計算方法とコスト最適化。
  </Card>
</CardGroup>
