> ## 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에서 최신 DEX 거래 10건**을 가져오며, 블록 시각, 트랜잭션 해시, 매수/매도 토큰 정보, 수량, 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](/ko/graphql/billing/graphql-billing)를 참고하세요.
</Info>

***

## 쿼리 수정해 보기

동작하는 쿼리를 얻었다면 아래 수정을 시도해 보세요.

<AccordionGroup>
  <Accordion title="Ethereum으로 전환">
    `network: sol`을 `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="Schema & Data Model" icon="diagram-project" href="/ko/graphql/schema/schema-overview">
    25개 Cube, 필드 타입, 필터 연산자, 집계 함수를 살펴봅니다.
  </Card>

  <Card title="Query Examples" icon="flask" href="/ko/graphql/examples/dex-trades">
    DEX 거래, 전송, OHLC, 홀더 등 실전 쿼리 예시를 둘러봅니다.
  </Card>

  <Card title="GraphQL IDE Guide" icon="code" href="/ko/graphql/ide/introduction">
    IDE 마스터하기 — 쿼리 템플릿, 저장된 쿼리, Variables 패널, 코드보내기.
  </Card>

  <Card title="Billing & Credits" icon="credit-card" href="/ko/graphql/billing/graphql-billing">
    쿼리 크레딧 계산 방식과 비용 최적화를 이해합니다.
  </Card>
</CardGroup>
