Sub topic 2
Getting around Dune: the query editor, engine and credits
Assume you know basic SQL and understand that blockchain activity is stored as blocks, transactions, logs, and traces. This chapter focuses on how Dune turns SQL into results and how to use its editor without wasting query credits.
The Dune workflow
Dune is a hosted analytics platform. You write SQL in a browser, Dune runs it against indexed blockchain tables, and the result can become a chart, a dashboard tile, or a reusable query.
The main parts are:
- Query editor: The workspace where you write SQL, select a blockchain dataset, run queries, and inspect results.
- DuneSQL engine: The execution system that parses your SQL, plans the work, reads the required tables, and returns rows.
- Query result: The rows returned by the engine. You can inspect them as a table or use them to create visualizations.
- Credits: A usage unit for query execution. Expensive queries consume more credits than small, selective queries. Your plan determines the available allowance and exact billing rules.
A saved query is separate from a dashboard. Saving preserves the SQL and its settings. A dashboard uses one or more saved queries to present results to other people.
Running a first query
Open a new query in the editor and begin with a small result set:
SELECT
block_time,
tx_hash,
project,
amount_usd
FROM dex.trades
WHERE blockchain = 'ethereum'
ORDER BY block_time DESC
LIMIT 100;The editor usually provides syntax highlighting, autocomplete, and a run control. Use autocomplete to discover table and column names, but verify the generated SQL. Suggestions can include similarly named columns from different table layers.
When the query finishes, inspect:
- The returned columns and their data types.
- Whether the rows match the intended blockchain and time period.
- The execution duration and credit estimate shown by the interface.
- Any warnings about limits, missing data, or failed execution.
A successful query is not automatically a correct query. For example, LIMIT 100 makes a test fast, but it does not produce a complete measurement.
Understanding execution and credits
When you run SQL, Dune must scan data and perform operations such as filtering, grouping, sorting, and joining. These operations consume compute resources. Dune represents that usage with credits.
The exact credit cost depends on the current Dune plan and product behavior. Treat the displayed estimate as part of query development, not as an afterthought. Start with a narrow time range and a small row limit. Then remove the limit only after checking the logic.
Use this development sequence:
- Test table and column names with
LIMIT. - Add a selective date or block filter.
- Check a small aggregate.
- Add joins and visualizations only after the base result is correct.
- Save the finished query and record what its metric means.
Editor habits that prevent wasted work
Keep exploratory queries separate from production queries. Give saved queries descriptive names such as Ethereum DEX volume, daily. Add comments when a calculation has an important assumption.
Avoid repeatedly running a query while changing several things at once. Change one clause, run it, and compare the result. If a query fails, read the error near the reported line and reduce the query to the smallest failing example.
Use the result preview to learn the schema, but do not rely on preview rows to infer totals. Blockchain tables are large and often contain multiple records for one user action.
Exercise
Why should you add a narrow filter and a LIMIT clause before building a dashboard query?
Show answer
They reduce the amount of data processed while you test table names, columns, and logic. Remove or broaden them only after the query is correct and you understand its credit cost.