Dune SQL Crypto Examples for On-Chain Analysis
Learn how to use Dune Analytics SQL to analyze on-chain crypto data, track wallets, and find trading edges with real query examples.
Learn how to use Dune Analytics SQL to analyze on-chain crypto data, track wallets, and find trading edges with real query examples.
Most traders look at price charts. Smart traders look at what's actually happening on-chain — and Dune Analytics gives you the raw SQL power to do exactly that. Dune lets you query blockchain data like a database: wallets, transactions, DEX swaps, token flows, everything. If you've ever wondered where the big money is moving before price reacts, this is your answer.
Dune Analytics is a blockchain data platform that indexes on-chain data from Ethereum, Solana, Polygon, Base, Arbitrum, and more — then lets you query it using SQL (specifically a dialect called DuneSQL, which is based on Trino). Think of it as a giant spreadsheet of everything that's ever happened on these blockchains, and you get to run your own queries against it.
For traders, this is massive. You can answer questions that no price chart will ever tell you: How many wallets are holding a token for the first time? Are whales accumulating or distributing? Is liquidity growing or shrinking on a particular DEX pool? These signals often appear on-chain hours or days before they show up in price on Binance or Bybit.
Key Takeaway: On-chain data is the blockchain's financial statement. Traders who read it have information that the majority of retail traders simply don't have access to.
DuneSQL is SQL with some blockchain-specific flavor. If you've used SQL before, you'll feel at home within minutes. If you haven't, don't worry — the queries you need for trading analysis are actually pretty simple. The hardest part is knowing which tables to use.
Dune organizes its data into schemas. The most important ones for crypto traders are: `ethereum.transactions` for raw ETH transactions, `dex.trades` for aggregated DEX trading activity across protocols, `tokens.transfers` for ERC-20 token movements, and `prices.usd` for historical price data. These four tables alone will cover 80% of what you want to know.
Let's skip the theory and get into actual queries. These examples work in the Dune query editor today — just copy, paste, and modify the contract address or wallet for whatever you're researching.
Example 1: Find the top token holders and their recent activity. This is useful when you're researching a new token and want to know if the distribution looks healthy or if a few wallets control everything.
-- Top 20 holders of a token and their last transfer date
SELECT
"to" AS wallet,
SUM(value / 1e18) AS total_received,
MAX(block_time) AS last_active
FROM tokens.transfers
WHERE contract_address = 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 -- UNI token
AND block_time >= NOW() - INTERVAL '90' DAY
GROUP BY 1
ORDER BY total_received DESC
LIMIT 20
Example 2: Track DEX volume for a specific token pair over time. This shows you whether trading activity is growing, which often precedes price moves that you'd eventually see listed on Coinbase or OKX.
-- Daily DEX volume for a token
SELECT
DATE_TRUNC('day', block_time) AS day,
COUNT(*) AS trade_count,
SUM(amount_usd) AS volume_usd
FROM dex.trades
WHERE (token_bought_address = 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984
OR token_sold_address = 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984)
AND block_time >= NOW() - INTERVAL '30' DAY
GROUP BY 1
ORDER BY 1 ASC
Example 3: Identify whale accumulation by finding wallets that have been buying consistently without selling. This pattern often appears during accumulation phases before a major pump.
-- Wallets buying a token repeatedly (potential accumulators)
SELECT
taker AS wallet,
COUNT(*) AS buy_count,
SUM(amount_usd) AS total_bought_usd,
MIN(block_time) AS first_buy,
MAX(block_time) AS last_buy
FROM dex.trades
WHERE token_bought_address = 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984
AND block_time >= NOW() - INTERVAL '14' DAY
AND amount_usd > 10000 -- only meaningful trades
GROUP BY 1
HAVING COUNT(*) >= 3 -- bought at least 3 times
ORDER BY total_bought_usd DESC
LIMIT 50
Key Takeaway: Replace the contract address `0x1f9840...` in any query with the token you're researching. You can find contract addresses on Etherscan or CoinGecko.
One of the highest-value things you can do with Dune SQL is track specific whale wallets. The idea is simple: find wallets that consistently make profitable trades, then watch what they're buying before the crowd figures it out. Traders who do this on Binance spot markets and catch a move early can ride it all the way up.
The process has three steps: find profitable wallets, monitor their recent buys, and set up alerts when they make a move. Here's a query that scores wallets by their realized PnL on DEX trades — a useful starting point for identifying skilled traders.
-- Find wallets with high win-rate on token trades in the last 30 days
WITH buys AS (
SELECT
taker AS wallet,
token_bought_address AS token,
SUM(amount_usd) AS spent_usd,
MIN(block_time) AS first_buy
FROM dex.trades
WHERE block_time >= NOW() - INTERVAL '30' DAY
AND amount_usd BETWEEN 5000 AND 500000
GROUP BY 1, 2
),
sells AS (
SELECT
taker AS wallet,
token_sold_address AS token,
SUM(amount_usd) AS received_usd
FROM dex.trades
WHERE block_time >= NOW() - INTERVAL '30' DAY
AND amount_usd BETWEEN 5000 AND 500000
GROUP BY 1, 2
)
SELECT
b.wallet,
COUNT(DISTINCT b.token) AS tokens_traded,
SUM(COALESCE(s.received_usd, 0) - b.spent_usd) AS net_pnl_usd
FROM buys b
LEFT JOIN sells s ON b.wallet = s.wallet AND b.token = s.token
GROUP BY 1
HAVING SUM(COALESCE(s.received_usd, 0) - b.spent_usd) > 50000
ORDER BY net_pnl_usd DESC
LIMIT 30
Once you have a list of consistently profitable wallets, add them to a watchlist. Platforms like VoiceOfChain can complement this by alerting you to price momentum signals in real time — so you're watching both on-chain wallet activity and live market movement simultaneously. When a whale you're tracking starts buying and VoiceOfChain shows a bullish signal on the same token, that's a high-conviction setup.
Beyond whale tracking, Dune SQL is invaluable for evaluating DeFi protocols before you commit capital. Is TVL actually growing, or is one whale inflating the numbers? Are users returning or churning? Is the protocol generating real revenue? These questions matter whether you're yield farming or trading the protocol's governance token on platforms like Gate.io or KuCoin.
Here's a query pattern for checking unique active users on a protocol — a far more honest health metric than TVL alone:
-- Weekly unique users interacting with a protocol contract
SELECT
DATE_TRUNC('week', block_time) AS week,
COUNT(DISTINCT "from") AS unique_users,
COUNT(*) AS total_transactions
FROM ethereum.transactions
WHERE "to" = 0x7a250d5630b4cf539739df2c5dacb4c659f2488d -- Uniswap V2 Router
AND success = TRUE
AND block_time >= NOW() - INTERVAL '180' DAY
GROUP BY 1
ORDER BY 1 ASC
| Use Case | What to Query | Trading Insight |
|---|---|---|
| Whale tracking | dex.trades by wallet | Front-run large accumulation |
| Token distribution | tokens.transfers | Spot unhealthy concentration |
| DEX volume trends | dex.trades by token | Identify rising interest early |
| Protocol health | ethereum.transactions | Evaluate DeFi before aping in |
| New wallet growth | tokens.transfers unique senders | Gauge new user adoption |
Running queries manually is useful, but the real power comes from scheduling them and building alerts. Dune lets you schedule queries to run automatically and has an API you can connect to your own systems. A common workflow is: run a query every hour, check if whale accumulation crossed a threshold, send an alert to Telegram.
Here's how this plays out practically. Say you're monitoring a mid-cap token listed on both Bybit and OKX. You have a Dune query that tracks net token flow for wallets holding over $100k. When that number turns sharply positive — whales buying significantly more than they're selling — you get an alert. You check VoiceOfChain to see if there's a corresponding price signal forming. If both align, you have a data-driven entry rather than a gut-feel trade.
Key Takeaway: On-chain data alone isn't enough — combine it with price action signals. On-chain tells you WHAT is happening; price action tells you WHEN the market is reacting.
Dune SQL is one of those tools that compounds in value the more you use it. Start with the examples in this article — swap in the token or wallet you care about, run the query, and see what you find. Over time you'll build a library of queries that gives you a real information edge over traders who only look at candlestick charts.
The best traders combine multiple data layers: on-chain analytics from Dune, real-time price signals from platforms like VoiceOfChain, and order book depth from exchanges like Binance and Bybit. No single layer tells the full story. On-chain data shows the smart money's hand. Price signals show when the market is finally catching up. That combination — data-driven patience followed by decisive execution — is what separates consistent traders from the crowd.
Key Takeaway: Fork existing Dune dashboards before building your own. The community has already solved most common on-chain analysis problems — start there and customize to your needs.