Onchain SQL

Query 106 ClickHouse tables directly with SQL — DEX trades, prices, transfers, DeFi metrics, prediction markets, and more.

Run SQL queries against Surf's on-chain data warehouse. 106 tables across 11 categories, accessible via the Data API's POST /onchain/sql endpoint or a readonly ClickHouse connection.

Quick Start

Via API:

curl -X POST https://api.asksurf.ai/gateway/v1/onchain/sql \
  -H "Authorization: Bearer <API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"query": "SELECT project, sum(amount_usd) AS vol FROM agent.ethereum_dex_trades WHERE block_date = today() - 1 GROUP BY project ORDER BY vol DESC LIMIT 10"}'

Via ClickHouse client:

SettingValue
ProtocolHTTPS (port 8443)
Useragent (readonly)
Databaseagent (all tables — the only database exposed)
Max execution time120 s
Max memory16 GB
Max result rows1 M

Table Discovery

Use the GET /onchain/schema endpoint to get all table names, columns, and types programmatically. Or browse the reference pages below.

Tables at a Glance

CategoryTablesChains / PlatformsWhat's in it
DEX Trades13ETH, Base, Arb, BSC, Tron, HyperEVM, TempoEvery swap event with USD amounts and protocol name, plus Tempo pair/pool registries
Prices7ETH, Base, Arb, Tron, HyperEVM, TempoDaily token prices (CoinGecko + DEX VWAP)
Token Metadata4ETH, Base, Arb, BSCERC-20 address → symbol / name / decimals
Transfers6ETH, Base, Arb, BSC, Tron, TempoERC-20 + native transfers with USD pricing
TVL / Fees / Yields15ETH, Base, Arb, Tron, Tempo (TVL); ETH, Base (fees, yields, top pools)Protocol- and pool-level daily TVL, fee revenue, pool APY
Lending & Staking2ETHLending flows + beacon chain staking by entity
Bridges & Payments5ETH-centric, TempoCross-chain bridge volume + Tempo MPP payment analytics
Prediction Markets31Polymarket, KalshiTrades, markets, prices, volume, OI, positions, smart money, custom views
Hyperliquid10Hyperliquid L1Perp snapshots, fills, trade episodes, wallet performance, funding, metadata
Chain Metrics10ETH, Base, Arb, TempoDaily tx count, active addresses, gas, contract deploys, fees, cohorts
Stablecoin3TempoDaily stablecoin supply changes and per-token activity metrics

Essential Rules

These apply to every query. Ignore them and your queries will be slow or wrong.

  1. Always filter on block_date first. It's the partition key on almost every table. Without it, ClickHouse scans the entire table.

  2. Use FINAL on ReplacingMergeTree tables. Hyperliquid tables and most Tempo daily-aggregate tables use this engine. Syntax: FROM table_name FINAL (place FINAL after the table name, before any alias).

  3. Handle NULLs explicitly. ClickHouse silently drops NULL rows in WHERE filters. Use ifNull(col, default) or coalesce().

  4. amount_usd is one-sided. DEX trade USD values follow DefiLlama methodology — they represent the token_sold side. Multiply by 2 for two-sided volume.

  5. USD prices come from CoinGecko. Hourly snapshots, not tick-level. New, illiquid, or unpriced tokens will have NULL amount_usd.

Data Freshness

SourceScheduleTypical Lag
Ethereum, Arbitrum, Bitcoin, TronDaily (BQ export)~1 day
BaseSensor (6h, cryo)~6 hours
BSCSensor (6h, cryo)~6 hours
TempoSensor (60 min, cryo)~1 hour
HyperEVMDaily (S3)~1 day
Hyperliquid (API)Hourly~1 hour
CoinGecko pricesHourly~1 hour
KalshiEvery 15 min (API)~15 min
Polymarket (on-chain)Every 30 min (BQ)~1 hour
Polymarket (real-time)Every 30 min (WebSocket)~30 min
dbt modelsPost-ingestion+30 min

Check freshness for any table:

SELECT max(block_date) FROM agent.<table_name>

Common Join Keys

FromToJoin column
Any table with token_addressToken symbol/nameJOIN agent.ethereum_erc20 ON contract_address
Polymarket tablesMarket questionJOIN agent.polymarket_market_details ON condition_id
Kalshi tablesMarket categoryJOIN agent.kalshi_market_details ON market_ticker (has category / subcategory)
Hyperliquid tablesContract metadataJOIN agent.hyperliquid_perp_meta ON coin
DeFi tablesTVL contextJOIN agent.ethereum_tvl_daily ON (project, version, block_date)

For query patterns and worked examples, see Common Patterns.

Surf — Crypto Intelligence for AI Agents