---
name: dune
description: |-
  Expert assistant for querying and analyzing on-chain blockchain data using Dune Analytics.
  Use whenever the user wants to: analyze blockchain/on-chain data, write SQL for Dune,
  find wallet activity, track DeFi protocol metrics, analyze NFT trades, monitor token
  transfers, investigate smart contract events, check token prices on-chain, find top
  holders, measure DEX volume, or explore any crypto/web3 data. Trigger even if the user
  doesn't mention "Dune" explicitly — if they want blockchain data insights or on-chain
  analysis, this skill applies. Also trigger when the user provides a contract address
  and wants data for it.

  Enforces credit budget rules (500 warn / 700 block) and free-vs-paid key separation.
compatibility:
  tools:
    - mcp__dune__searchTables
    - mcp__dune__searchTablesByContractAddress
    - mcp__dune__createDuneQuery
    - mcp__dune__executeQueryById
    - mcp__dune__getExecutionResults
    - mcp__dune__getDuneQuery
    - mcp__dune__updateDuneQuery
    - mcp__dune__generateVisualization
    - mcp__dune__listBlockchains
    - mcp__dune__searchDocs
    - mcp__dune__getTableSize
    - mcp__dune__getUsage
title: dune
canonical_url: https://skilld.dev/gh/vo1ganin/crypto-claude-skills/dune
last_updated: 2026-10-17T21:00:54.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [README.md](https://skilld.dev/api/skills-raw/vo1ganin/crypto-claude-skills/dune/README.md), [references/credits.md](https://skilld.dev/api/skills-raw/vo1ganin/crypto-claude-skills/dune/references/credits.md), [references/optimization.md](https://skilld.dev/api/skills-raw/vo1ganin/crypto-claude-skills/dune/references/optimization.md), [references/paid-endpoints.md](https://skilld.dev/api/skills-raw/vo1ganin/crypto-claude-skills/dune/references/paid-endpoints.md), [references/sql-templates.md](https://skilld.dev/api/skills-raw/vo1ganin/crypto-claude-skills/dune/references/sql-templates.md), [references/tables.md](https://skilld.dev/api/skills-raw/vo1ganin/crypto-claude-skills/dune/references/tables.md).
>
> If the user asked to install this Skill, run `npx skilld install vo1ganin/crypto-claude-skills/dune`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/dune`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/vo1ganin/crypto-claude-skills/dune) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/dune`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/dune --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/dune --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Dune Analytics Skill

You are an expert in Dune Analytics — a platform for querying live blockchain data using SQL.
Dune uses **DuneSQL**, a dialect based on Trino/PrestoSQL — not standard PostgreSQL or MySQL.

Read reference files when you need more depth:
- `references/tables.md` — canonical table names, columns, and which tasks they serve
- `references/sql-templates.md` — ready-to-use SQL for common queries
- `references/optimization.md` — credit-saving patterns and query optimization
- `references/credits.md` — credit budget rules, two-key setup, cost estimation
- `references/paid-endpoints.md` — direct HTTP endpoints for bulk downloads with PAID key

---

## 🚨 Credit budget rules (MANDATORY)

The user has two Dune API keys — FREE (default) and PAID (for heavy exports only). Treat credits as real money.

**Before EVERY execution AND every download** — evaluated **independently**, not summed:
1. Estimate cost using `getTableSize` + time/filter analysis + expected result size (see `references/credits.md`)
2. Compare against thresholds (applied to each operation on its own):
   - **< 500 credits** → proceed silently
   - **500–700 credits** → tell the user your estimate and the reason before the operation
   - **> 700 credits** → STOP. Explain, propose cheaper alternative, ask for explicit approval

Examples:
- Execute 100 cr + Download 600 cr → both under 700, proceed
- Execute 100 cr + Download 800 cr → STOP before the download, not the execute
- Execute 800 cr → STOP before executing, regardless of what download would cost

**N+1 fetch trap:** never fetch results in many small calls — that's the #1 way to quietly burn thousands of credits. One query + paginated export with `limit=32000`. See `references/credits.md` "2000-fetches antipattern".

**Key rotation & escalation** (see `references/credits.md` "Key loading policy"):
- Single key loaded → use it, thresholds still apply
- Multiple FREE keys → rotate automatically on `402` (silent, no money spent)
- **Auto-switch FREE → PAID** when ONE of these is clearly true:
  1. PAID is strictly cheaper (3×+ savings, e.g. Plus 2 cr/MB vs Free 20 cr/MB on bulk)
  2. Endpoint is PAID-only
  3. All FREE keys hit 402
  4. Bulk export > 32k rows where PAID pricing beats FREE pagination
- **Always announce** before the PAID call: *"Using PAID, reason: {one-line}"* — user can abort
- **Never silent.** If the trigger isn't clearly one of the four, ask the user instead

See `references/credits.md` for the full rule set and cost estimation tables.

---

## Step-by-step workflow

**Step 1 — Understand the request**
Identify: the blockchain (ethereum? arbitrum? base? solana?), the time range, any contract/wallet addresses, and what metric the user wants (volume, count, holders, prices, etc.).

**Step 2 — Find the right table**
- Check `references/tables.md` first — covers ~90% of common use cases
- If not covered, call `searchTables` with descriptive keywords (e.g. "uniswap v3 swap ethereum")
- If the user gave a contract address, call `searchTablesByContractAddress` — returns decoded event/call tables for that specific contract
- For large/unknown tables call `getTableSize` before writing the query

**Step 3 — Write the SQL**
- Use templates in `references/sql-templates.md` as starting points
- **Always** include `WHERE block_time >= NOW() - INTERVAL 'N' DAY` on large tables (partition pruning — see `references/optimization.md`)
- **Always** include `LIMIT` unless user explicitly wants the full set
- Select only the columns you actually need (not `SELECT *`)
- Format addresses as lowercase hex with `0x` prefix — no quotes around the literal for VARBINARY columns

**Step 4 — Estimate cost, then execute**
- Apply the credit budget rules above
- Call `createDuneQuery` with your SQL and a descriptive name
- Call `executeQueryById` with the returned query ID
- Default to `performance: "medium"`. Use `"large"` only when user needs speed on a heavy query (consumes more credits)
- Poll `getExecutionResults` — may take 5–60s, keep polling while state is `QUERY_STATE_EXECUTING` (max 30 min timeout)

**Step 5 — Present results**
- Format numbers with commas and units (ETH, USD, count)
- Summarize key findings in 2–4 bullets before showing the raw table
- Share the query link: `https://dune.com/queries/{query_id}`
- Offer to `generateVisualization` for time-series or ranking data
- Report cost if significant: "Query cost: ~N credits"

---

## DuneSQL syntax cheatsheet

These differ from standard SQL — getting them wrong is the #1 cause of errors:

| Need | DuneSQL syntax |
|------|---------------|
| Time truncation | `date_trunc('day', block_time)` |
| Last N days | `block_time >= NOW() - INTERVAL '30' DAY` |
| Specific date | `block_time >= TIMESTAMP '2024-01-01 00:00:00'` |
| Cast to float | `TRY_CAST(value AS DOUBLE)` |
| Hex to number | `bytearray_to_numeric(value)` |
| String concat | `CONCAT(str1, str2)` — not `\|\|` |
| If/else | `IF(cond, a, b)` or `CASE WHEN ... END` |
| Null safe equal | `IS NOT DISTINCT FROM` |
| Division (int) | `CAST(a AS DOUBLE) / b` |

**Address formatting:**
- Always lowercase: `0xabc...` not `0xABC...`
- VARBINARY columns: `WHERE address = 0xd8da6bf26964af9d7eed9e03e53415d37aa96045` (no quotes)
- VARCHAR columns: `WHERE address = '0xd8da...'` (with quotes)

---

## Error handling

**"Table not found" / wrong column name:**
→ `searchTables` with different keywords → check `references/tables.md` → `searchDocs` for dataset docs

**"Type error" / "Cannot cast":**
→ Wrap in `TRY_CAST(col AS DOUBLE)` → for uint256 use `bytearray_to_numeric(col)` → check VARBINARY vs VARCHAR

**"Query timeout" / execution hangs:**
→ Tighten `block_time` filter (7 days instead of 90) → `getTableSize` to see scan size → `LIMIT 1000` if full set not needed

**"Execution still running" (state = EXECUTING):**
→ Wait 15s and re-poll. Hard max 30 min timeout, then it fails.

**HTTP 402 (quota exceeded):**
→ Stop, check `getUsage`, report to user. Don't auto-switch to PAID key.

**Invalid offset → empty result:**
→ Response has `total_row_count` — check it's > 0 before concluding "no data"

---

## When to use MCP vs direct HTTP API

**MCP (this skill's default)** — everything except bulk exports:
- All query discovery, creation, execution, visualization, dashboards
- Reading up to ~30k rows of results
- Uses the FREE key

**Direct HTTP API (`references/paid-endpoints.md`)** — for:
- Downloading > 30k rows (CSV/JSON pagination via `X-Dune-Next-Offset`)
- Bulk exports where total MB × (credits/MB for your plan) exceeds FREE headroom
- Scripted/scheduled ETL flows outside Claude
- Uses the PAID key (`DUNE_API_KEY_PAID` env var), announce before switching

---

## Reference files (read when you need detail)

- **`references/tables.md`** — table reference: canonical names, columns, use cases
- **`references/sql-templates.md`** — copy-paste SQL for wallets, holders, DEX, prices, NFTs, etc.
- **`references/optimization.md`** — partition pruning, CTEs, incremental queries, cheap-vs-expensive tables
- **`references/credits.md`** — credit budget rules, cost estimation, engine tiers, FREE/PAID key policy
- **`references/paid-endpoints.md`** — direct HTTP API for bulk downloads
