← Protocols
Dune
01Description

Onchain SQL analytics platform. Author queries against decoded EVM and Solana data, expose results as JSON via the Dune API, and embed dashboards.

02Best for
  • 01onchain SQL analytics
  • 02custom dashboards
  • 03protocol KPIs
  • 04wallet/address breakdowns
  • 05powering data widgets in dapps
03Install
  • pnpm add @duneanalytics/client-sdk
04Environment variables
VariableScopeDescription
DUNE_API_KEYServerDune API key from team settings. Server-side only — never expose in the browser.
05Prompt snippet
Use the Dune API for onchain analytics. Author the query in the Dune UI to get a `queryId`, then from a server route call `POST https://api.dune.com/api/v1/query/{queryId}/execute` with the `X-Dune-Api-Key` header to get an `execution_id`. Poll `GET /api/v1/execution/{execution_id}/status` until state is `QUERY_STATE_COMPLETED`, then fetch `GET /api/v1/execution/{execution_id}/results`. Prefer `GET /api/v1/query/{queryId}/results` (cached latest) for read-mostly widgets to avoid burning execution credits, and use parameters for user-supplied filters instead of string-concatenating SQL. The official `@duneanalytics/client-sdk` wraps these endpoints with a `refresh()` helper.
06Gotchas
  • Free tier has tight monthly execution credits and low rate limits — cache results aggressively in your own DB or KV and use the `latest` results endpoint instead of re-executing.
  • Dune indexes EVM chains and Solana but does NOT cover every chain (Bitcoin, Cosmos, Sui, Aptos, Move-based L1s are largely absent) — verify dataset coverage before promising analytics on a niche chain.
  • Query execution is asynchronous — never call `/execute` from a user-facing request handler without queueing; long queries can take minutes.
  • `DUNE_API_KEY` must stay server-side; exposing it in `NEXT_PUBLIC_*` lets anyone drain your credits.
  • Decoded contract tables lag behind raw `transactions`/`logs` tables — for newly deployed contracts, decode manually or submit a decoding request.
07Alternatives