跳转到主要内容

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(以 cs_live_... 开头)
GraphQL API 与 REST Data API 共用同一 API Key。若你已有 REST API 的 Key,可直接在此复用。

第一步:获取 API Key

  1. 登录 ChainStream Dashboard
  2. 进入 Applications
  3. 点击 Create New App(或选择已有应用)
  4. 复制你的 API Key

第二步:打开 GraphQL IDE

访问 ChainStream GraphQL IDE: IDE 提供自动补全、语法高亮、内联文档与查询历史 — 是探索 schema 与编写查询最快的方式。

第三步:配置鉴权

在 IDE 中打开 Headers 面板(左下角),添加 API Key:
{
  "X-API-KEY": "your_api_key"
}

第四步:运行示例查询

将以下查询粘贴到编辑器。它会拉取 Solana 上最近 10 笔 DEX 成交,含区块时间、交易哈希、买卖代币信息、数量、USD 价格与 DEX 协议名。
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 }
      }
    }
  }
}
在 GraphQL IDE 中打开 — 粘贴上方查询即可交互运行,并享受自动补全与 schema 浏览。
点击 Play 按钮(或按 Ctrl+Enter / Cmd+Enter)执行。

cURL 等价写法

你也可以在终端运行相同查询:
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 } } } } }"
  }'

响应示例

成功响应大致如下:
{
  "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.SlotSolana slot 编号(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)
extensions.credits 对象展示本次查询消耗的计费额度与余额。详见 计费与额度

尝试修改查询

查询跑通后,可以试试这些改法:
将根从 Solana 改为 EVM(network: eth) 并相应调整查询体,以查询 Ethereum DEX 成交(Uniswap、SushiSwap 等)。
通过 where 筛选最近一小时的成交:
Solana {
  DEXTrades(
    limit: {count: 10}
    orderBy: {descending: Block_Time}
    where: {Block: {Time: {after: "2025-03-27T09:00:00Z"}}}
  ) { ... }
}
按代币 mint 地址筛选,查看该代币的成交:
Solana {
  DEXTrades(
    limit: {count: 10}
    orderBy: {descending: Block_Time}
    where: {Trade: {Buy: {Currency: {MintAddress: {is: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}}}}}
  ) { ... }
}
按 DEX 协议统计成交笔数:
Solana {
  DEXTrades(
    where: {Block: {Time: {after: "2025-03-27T00:00:00Z"}}}
  ) {
    count
    Trade { Dex { ProtocolName } }
  }
}

下一步

Schema 与数据模型

浏览全部 25 个 Cube、字段类型、筛选运算符与聚合函数。

查询示例

查看 DEX 成交、转账、OHLC、持有人等实际查询示例。

GraphQL IDE 指南

掌握 IDE — 查询模板、保存查询、变量面板与代码导出。

计费与额度

了解查询额度如何计算以及如何优化成本。