跳轉到主要內容

GraphQL 端點

所有 GraphQL 查詢發往同一端點:
https://graphql.chainstream.io/graphql
同時支援 POSTGET
MethodContent-Type使用場景
POSTapplication/json推薦用於所有查詢 —— 支援 variables 與複雜查詢
GET查詢字串(?query=...簡單查詢、瀏覽器測試、利於快取
生產環境請使用 POST。GET 將查詢編碼在 URL 中,存在長度限制,複雜查詢不便使用。

認證

X-API-KEY 請求頭中傳入 API Key 即可完成認證。與 REST Data API 使用同一 API Key,無需單獨憑證。
X-API-KEY: your_api_key
ChainStream DashboardApplicationsCreate New App 獲取 API Key。Key 以 cs_live_... 開頭。

必填請求頭

HeaderValue是否必填
Content-Typeapplication/json是(POST)
X-API-KEYcs_live_...

請求格式

GraphQL 請求體為包含兩個欄位的 JSON 物件:
FieldType說明
querystringGraphQL query 或 mutation 字串
variablesobject可選,在查詢中透過 $variable 語法引用的變數

POST 示例

curl -X POST "https://graphql.chainstream.io/graphql" \
  -H "Content-Type: application/json" \
  -H "X-API-KEY: your_api_key" \
  -d '{
    "query": "query ($network: Network!) { DEXTrades(network: $network, limit: {count: 5}) { Block { Time } Trade { Buy { Currency { MintAddress } Amount } } } }",
    "variables": { "network": "sol" }
  }'

GET 示例

curl -G "https://graphql.chainstream.io/graphql" \
  -H "X-API-KEY: your_api_key" \
  --data-urlencode 'query={ DEXTrades(network: sol, limit: {count: 5}) { Block { Time } } }'

支援的網路

在每個頂層 Cube 查詢上將 network 作為列舉傳入:
Network EnumBlockchainChain ID
solSolana
ethEthereum1
bscBNB Chain (BSC)56
# Solana
{ DEXTrades(network: sol, limit: {count: 5}) { ... } }

# Ethereum
{ DEXTrades(network: eth, limit: {count: 5}) { ... } }

# BSC
{ DEXTrades(network: bsc, limit: {count: 5}) { ... } }

響應格式

所有響應均為 JSON,結構如下:
{
  "data": {
    "DEXTrades": [
      { "Block": { "Time": "2025-03-27T10:15:30Z" }, "..." : "..." }
    ]
  },
  "extensions": {
    "credits": {
      "total": 50,
      "cubes": [
        { "cube": "DEXTrades", "credits": 50, "row_count": 5 }
      ]
    }
  }
}
Field說明
data查詢結果 —— 與查詢結構一致
errors僅在存在校驗或執行錯誤時出現
extensions.credits.total本次查詢消耗的 credit 單位總計
extensions.credits.cubes按 Cube 拆分:Cube 名稱、計費 credits 與返回行數
在產生 credits 消耗時,響應會包含 extensions.credits 欄位。Credits 計算方式見 計費與額度

錯誤響應

當查詢格式錯誤或執行失敗時,響應會包含 errors 陣列:
{
  "data": null,
  "errors": [
    {
      "message": "Unknown field 'InvalidField' on type 'DEXTrades'",
      "locations": [{ "line": 3, "column": 5 }]
    }
  ]
}
在接入應用前,可使用 GraphQL IDE 互動式校驗查詢。IDE 提供自動補全與行內錯誤高亮。

下一步

執行首次查詢

跟隨分步教程,在 IDE 或 cURL 中執行真實查詢。

探索 Schema

深入瞭解 25 個 Cube、欄位型別、過濾運算子與聚合函式。