> ## 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](/cn/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 总览](/cn/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 安装](/cn/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="/cn/docs/access-methods/rest-api">
    按需查询——代币、钱包、池子、交易、合规。
  </Card>

  <Card title="GraphQL" icon="diagram-project" href="/cn/docs/access-methods/graphql">
    针对整个链上数据 cube 的灵活分析查询。
  </Card>

  <Card title="WebSocket" icon="tower-broadcast" href="/cn/docs/access-methods/websocket">
    面向实时 UI 与浏览器应用的亚秒级推送。
  </Card>

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

  <Card title="SDK" icon="box" href="/cn/sdks/overview">
    TypeScript / Python / Go / Rust，内置鉴权的类型化客户端。
  </Card>

  <Card title="CLI" icon="terminal" href="/cn/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 次/秒，请升级或按指数回退。
    详见 [计费与额度](/cn/docs/platform/billing-payments/plans-and-units)。
  </Accordion>

  <Accordion title="如何查询其他链的代币？">
    替换 URL 中的链标识即可：`solana`、`ethereum`、`bsc`、`base`、`polygon`、
    `arbitrum`、`optimism`、`avalanche`、`zksync`、`tron`。
    完整列表见 [支持的链](/cn/docs/supported-chains)。
  </Accordion>
</AccordionGroup>

## 下一步

<CardGroup cols={2}>
  <Card title="浏览数据目录" icon="boxes-stacked" href="/cn/docs/data-products/overview">
    我们发布的每个数据集与覆盖范围、刷新频率。
  </Card>

  <Card title="启动实时流" icon="tower-broadcast" href="/cn/docs/access-methods/websocket">
    订阅实时交易、价格、转账、池子事件。
  </Card>

  <Card title="运行合规检查" icon="shield-halved" href="/cn/docs/compliance/overview">
    对转账、提现、对手方的 KYT / KYA。
  </Card>

  <Card title="构建 AI Agent" icon="robot" href="/cn/docs/ai-agents/overview">
    通过 MCP + Agent Skills 接入 Claude、Cursor、ChatGPT。
  </Card>
</CardGroup>
