Dune for dummies

Chris Ahn
Web3 Surfers
Published in
4 min readJul 10, 2022

Learn basic data analytics for on-chain data in 5 minutes !

One of the major breakthroughs of blockchain and web3 technology is that now, any data on transactions, exchanges, transfers that occur on-chain can be viewed by anyone with an internet connection. On-chain data is transparent, immutable, and immediately accessible on numerous platforms, such as block explorers like Etherscan.

However, this process of accessing on-chain data through block explorers can sometimes be tedious and cumbersome, especially when needing large quantities of data with very specific types of filters. This is where Dune, an on-chain data analytics platforms, comes in very handy.

No not that Dune !

Dune stores information on transactions that occur on various blockchains on a regular basis, in the form of an SQL (structured query language) database. Simply put, an SQL database is a type of database where information is saved in relational tables, and people can easily query information on this database by writing very simple SQL code. The advantage of accessing data this way is that it is highly customizable and scalable. Also, since a lot of coders already have some basic knowledge on SQL, the onboarding process is quite fast and easy. Let’s go over some simple query commands that allow you to fetch and retrieve data on transactions.

The most basic SQL commands are:

  • SELECT
  • FROM
  • WHERE

Let’s look at a very basic example:

https://dune.com/queries/1020912

The above query is one of the most basic commands you can find, and is very simple:

  • with SELECT, you tell the program what information you want to retrieve. Here I used a * to tell the program I want to get all the information from the table.
  • with FROM (this part comes after SELECT), you tell the program where you want it to look the information for. As I said earlier, data on SQL databases are saved in tables, so we’re telling which tables should be looked at. In our example, I’m asking to look for the table called erc20.“ERC20_evt_Transfer”, which is basically the table containing information on transactions of ERC20 tokens that occur on the Ethereum blockchain.
  • LIMIT(10) just tells the code to retrieve only the 10 latests transactions (asking for all transactions that occurred on the blockchain ever since its creation would take a bit too much time).

When running this query, we obtain the results in the form of a downloadable table (when downloaded, it is in a CSV format):

We can see that there’s a lot of columns in the result (“from”, “to”, “value”) so now let’s try to make a more specific query.

https://dune.com/queries/1020954

Here we have:

  • a SELECT clause where “value” and “evt_block_time” are retrieved, those are the names of the columns in the table that correspond to the value of the token transferred and at which time this transaction occurred.
  • a WHERE clause. WHERE clauses tell the program a specific condition, filter that you want went asking for more specific information. For instance, here we ask that the contract address, i.e. the hash address of the token that is being transferred, be equal to 0xdAC17F958D2ee523a2206206994597C13D831ec7 (in Dune, most addresses replace the leading 0 with a \). This hash address corresponds to that of USD Tether stablecoin, and so we’re limiting our search to look only at historical transactions of USDT.

The result this time is much more simple looking:

Of course, the wonders of Dune don’t end here. As it is a data analytics platform, it also offers the possibility of automatically drawing charts and graphs from the result you obtained and add them to dashboards, without writing another line of code ! Simply check out some of the dashboards that were obtained through Dune query lines:

Examples of cool dashboards you can easily make on Dune (source: https://dune.com/haechi_research/curve-finance-pool)

See, data analytics isn’t too hard! We’ve gone over some basic fundamentals of Dune, and next time we’ll take a look at more sophisticated that allow you get cool graphs like the ones above !

Thanks for reading the article😊😊😊
Make sure to also follow us on our Web3 Surfers medium page!!!
https://medium.com/web3-surfers

--

--