Create your first query
Learn to analyze daily DEX trading volumes across different blockchains
New to Dune? Let’s start your analytics journey by creating an insightful query that analyzes daily DEX trading volumes across different blockchains. This guide will teach you the basics while delivering practical insights about DeFi trading activity.
Getting Started
Create a New Query: Head over to Create New Query to begin. Dune uses DuneSQL, a SQL dialect that is compatible with TrinoSQL. It is a fairly vanilla SQL dialect, but there are some nuances you will eventually encounter. If you are not familiar with SQL, you can learn the basics here.
Choosing the Right Table
Choosing the right table is the first step to creating a successful query. You can find the table you need in the Data Catalog.
-
Understanding curated data: Instead of working with complex raw blockchain data, we’ll use Dune’s curated data - a collection of pre-built, analytics-ready tables. Curated data standardizes data across chains and makes analysis much easier.
-
The Perfect Table: For DEX trading analysis, we’ll use the
dex.trades
table. This table contains standardized trading data across multiple DEXes and blockchains.
Building Your Query Step by Step
Let’s analyze DEX trading activity across different blockchains. We’ll start simple and build up our analysis:
- Select Key Metrics: For our DEX analysis, we’ll track:
- Block date (to see trends over time)
- Blockchain (to compare activity across networks)
- Trading volume in USD
- Number of trades
Here’s our query:
Understanding the Query Components
Each part of this query helps us analyze DEX activity:
block_date
: Groups all trades into daily bucketsblockchain
: Helps us compare activity across Ethereum, Polygon, Arbitrum, etc.COUNT(*)
: Gives us the trading frequencySUM(amount_usd)
: Shows the total value traded in USDWHERE block_date >= NOW() - INTERVAL '30 days'
: Focuses on recent activityGROUP BY 1, 2, 3
: Combines trades by day, blockchain, and DEXORDER BY 1 DESC, 5 DESC
: Shows newest and highest volume trades first
Making Your Analysis Dynamic with Parameters
Want to focus on your favorite DEX? Let’s add the column project
as a parameter to make the analysis interactive:
To add the parameter:
- Click “Add Parameter” below the query editor
- Create a text parameter named “Project Name”
- Set default value to “Uniswap”
Now you can instantly switch between different DEXes to compare their performance!
Visualizing Results
After running your query, you can create powerful visualizations:
- Click “New Visualization”
- Choose “Bar Chart”
- Set X-axis to
trading_day
- Set Y-axis to
trading_volume_usd
- Group by
blockchain
This will create a stacked bar chart showing daily trading volumes by blockchain!
Want to explore more? Try:
- Removing the project filter to see all DEXes
- Changing the time period to 7 days or 90 days
- Adding token filters to focus on specific cryptocurrencies
Next Steps
Congratulations on creating your first DEX analysis query! 🎉
You can find many more queries related to DEX trading activity in this dashboard: DEX Trading Activity
Save your query by clicking Save in the upper right corner. You can revisit and modify it anytime to explore different aspects of DEX trading activity.
Was this page helpful?