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

# 快速開始

> 5 分鐘內完成首次帶鑑權的 ChainStream 呼叫。

讀完本文後你將擁有：

* 一個 API Key（或 OAuth Token）
* 一次跑通的 REST API 呼叫
* 一次跑通的 SDK、CLI、MCP Server 呼叫
* 明確的下一步——REST / GraphQL / WebSocket / Kafka / SDK / CLI / MCP，哪個最適合你的場景

<Note>預計時間：**5 分鐘**。</Note>

## 前置條件

一個 ChainStream 賬號。如未註冊請到[這裡](https://www.chainstream.io/dashboard)。

## 1. 獲取 API Key

1. 開啟 [ChainStream Dashboard](https://www.chainstream.io/dashboard)。
2. 進入 **Applications**。
3. 點選 **Create New App**。
4. 複製生成的 **API Key**（`cs_live_…` 開頭）。

<Tip>
  API Key 是最快的接入方式。服務間（M2M）請參考 OAuth 2.0 client-credentials——見
  [API Key 與 OAuth](/zh-Hant/docs/platform/authentication/api-keys-oauth)。
</Tip>

## 2. 發起首次請求

下例取 Solana 上 Wrapped SOL 的後設資料。選你要接入的方式：

<Tabs>
  <Tab title="cURL">
    ```bash theme={null}
    curl "https://api.chainstream.io/v2/token/solana/So11111111111111111111111111111111111111112/metadata" \
      -H "X-API-KEY: your_api_key"
    ```
  </Tab>

  <Tab title="SDK (TypeScript)">
    ```typescript theme={null}
    import { ChainStreamClient } from "@chainstream-io/sdk";

    const cs = new ChainStreamClient({ apiKey: "your_api_key" });

    const token = await cs.token.getToken(
      "So11111111111111111111111111111111111111112",
      "solana",
    );

    console.log(token.name, token.symbol, token.decimals);
    ```

    其他語言（Python、Go、Rust）見 [SDK 總覽](/zh-Hant/sdks/overview)。
  </Tab>

  <Tab title="CLI">
    ```bash theme={null}
    # 无需安装，npx 会拉取最新 CLI。
    npx @chainstream-io/cli token info \
      --chain solana \
      --address So11111111111111111111111111111111111111112
    ```

    首次執行會提示輸入 Key，也可顯式設定：

    ```bash theme={null}
    npx @chainstream-io/cli config set --key apiKey --value your_api_key
    ```
  </Tab>

  <Tab title="MCP (AI Agent)">
    ```bash theme={null}
    CHAINSTREAM_API_KEY=your_api_key npx @chainstream-io/mcp
    ```

    之後向你的 Agent 提問 *"What is the SOL token on Solana?"*，它會自動選工具呼叫。

    Claude / Cursor / ChatGPT 的具體配置見
    [MCP Server 安裝](/zh-Hant/docs/ai-agents/mcp-server/setup)。
  </Tab>

  <Tab title="OAuth 2.0 (JWT)">
    OAuth 2.0 Client Credentials 流程：

    ```bash theme={null}
    curl -X POST "https://dex.asia.auth.chainstream.io/oauth/token" \
      -H "Content-Type: application/json" \
      -d '{
        "client_id": "YOUR_CLIENT_ID",
        "client_secret": "YOUR_CLIENT_SECRET",
        "audience": "https://api.dex.chainstream.io",
        "grant_type": "client_credentials"
      }'

    curl "https://api.chainstream.io/v2/token/solana/So11111111111111111111111111111111111111112/metadata" \
      -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
    ```
  </Tab>
</Tabs>

### 響應

```json theme={null}
{
  "chain": "solana",
  "address": "So11111111111111111111111111111111111111112",
  "name": "Wrapped SOL",
  "symbol": "SOL",
  "decimals": 9,
  "imageUrl": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png",
  "tokenCreatedAt": 1710417600000
}
```

| 欄位               | 型別      | 說明              |
| :--------------- | :------ | :-------------- |
| `chain`          | string  | 鏈標識，小寫。         |
| `address`        | string  | 合約地址。           |
| `name`           | string  | 代幣全名。           |
| `symbol`         | string  | 代幣符號。           |
| `decimals`       | integer | 精度。             |
| `imageUrl`       | string  | Logo URL（可能為空）。 |
| `tokenCreatedAt` | integer | 建立時間戳（ms）。      |

## 3. 選擇合適的接入方式

上面只是一次簡單的請求-響應呼叫，真實整合通常需要更多：

<CardGroup cols={2}>
  <Card title="REST API" icon="bolt" href="/zh-Hant/docs/access-methods/rest-api">
    按需查詢——代幣、錢包、池子、交易、合規。
  </Card>

  <Card title="GraphQL" icon="diagram-project" href="/zh-Hant/docs/access-methods/graphql">
    針對整個鏈上資料 cube 的靈活分析查詢。
  </Card>

  <Card title="WebSocket" icon="tower-broadcast" href="/zh-Hant/docs/access-methods/websocket">
    面向實時 UI 與瀏覽器應用的亞秒級推送。
  </Card>

  <Card title="Kafka Streams" icon="bars-staggered" href="/zh-Hant/docs/access-methods/kafka-streams/overview">
    面向後端、索引器、交易引擎的 exactly-once 投遞。
  </Card>

  <Card title="SDK" icon="box" href="/zh-Hant/sdks/overview">
    TypeScript / Python / Go / Rust，內建鑑權的型別化客戶端。
  </Card>

  <Card title="CLI" icon="terminal" href="/zh-Hant/docs/access-methods/cli">
    指令碼、CI/CD，以及 AI Agent 的按次付費呼叫。
  </Card>
</CardGroup>

## 常見問題

<AccordionGroup>
  <Accordion title="401 Unauthorized">
    * 確認請求頭中 `X-API-KEY` 或 `Authorization: Bearer …` 拼寫正確。
    * Key 被輪換過請重新生成。
    * OAuth 模式下檢查 token 是否過期（預設 TTL 1 小時）。
  </Accordion>

  <Accordion title="429 Too Many Requests">
    達到套餐限速。免費套餐為 10 次/秒，請升級或按指數回退。
    詳見 [計費與額度](/zh-Hant/docs/platform/billing-payments/plans-and-units)。
  </Accordion>

  <Accordion title="如何查詢其他鏈的代幣？">
    替換 URL 中的鏈標識即可：`solana`、`ethereum`、`bsc`、`base`、`polygon`、
    `arbitrum`、`optimism`、`avalanche`、`zksync`、`tron`。
    完整列表見 [支援的鏈](/zh-Hant/docs/supported-chains)。
  </Accordion>
</AccordionGroup>

## 下一步

<CardGroup cols={2}>
  <Card title="瀏覽資料目錄" icon="boxes-stacked" href="/zh-Hant/docs/data-products/overview">
    我們釋出的每個資料集與覆蓋範圍、重新整理頻率。
  </Card>

  <Card title="啟動實時流" icon="tower-broadcast" href="/zh-Hant/docs/access-methods/websocket">
    訂閱實時交易、價格、轉賬、池子事件。
  </Card>

  <Card title="執行合規檢查" icon="shield-halved" href="/zh-Hant/docs/compliance/overview">
    對轉賬、提現、對手方的 KYT / KYA。
  </Card>

  <Card title="構建 AI Agent" icon="robot" href="/zh-Hant/docs/ai-agents/overview">
    透過 MCP + Agent Skills 接入 Claude、Cursor、ChatGPT。
  </Card>
</CardGroup>
