or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
🚨 Our docs have moved to docs.dune.xyz 🚨
Here are some tips and tricks on how to get started with the data and interface.
👇 Top links
Create a user for free at duneanalytics.com 👍
Submit contracts for decoding at duneanalytics.com/decode 📥
Browse curated dashboards, queries and data tables for top projects duneanalytics.com/projects or add a project via a simple markdown file 🗂
Find and create data abstractions via our public Github 💻
Can't find what you're looking for? Ask our community on our Discord server or email us at support@duneanalytics.com 👩🔧
📚 Need some help getting started with queries?
See this 20 min intro video on how to create queries on Dune 📹
Here's a good getting started article, even if you don't know SQL 🗒
Many non-technical users have mastered Dune with no prior codeing experience. Dune is powered by the very common database PostgreSQL and you can find a ton of resources by searching online, both for getting started with SQL (udemy, codecademy etc.) and for any query specific question 🧠
Dune Analytics TLDR
1. Query human-readable smart contract data with PostgreSQL 🔍
2. Visualize your findings 📊
3. Create dashboards and share them with public links 🌎
4. Explore analysis created by other community members. You can fork any query by the click of a button. 👨👩👦👦
👉 Create a user for free at duneanalytics.com
Table of contents
🗂 Data tables
You can currently query data from Ethereum mainnet and xdai.
To query xDai data change the data source in the dropdown list above the data table list on the query page.
The most commonly used tables are
dex.trades
lending.borrow
,lending.collateral_change
,lending.repay
stablecoin.transfer
,stablecoin.mint
,stablecoin.burn
10
to the power ofdecimals
from this table.ethereum.transactions.hash = evt_tx_hash
.Decoded smart contract data
Instead of working with the traces, logs, and receipts, Dune decodes smart contract activity into nice human-readable tables. See the this section for more info.
Submit contracts for decoding at duneanalytics.com/decode.
Abstractions/table views
These are the cleanest and easiest to use tables on Dune. We have abstractions for dex trades in the
dex.trades
table.You can also search for
view
in our table list to find all the various views.Together with various teams and community members we've created table views that make the blockchain data even easier to work with. This typically entails removing decimals for ETH and token transfers, adding human readable symbols, joining relevant tables together, adding USD value of events and more.
You can always see the underlying tables derived directly from the blockchain if you need more details or are curious about how the views are created: check out our Github, you can even do a pull request to create your own abstractions.
Raw Ethereum data
You probably won't use this too much when doing analysis with Dune (see decoded data), but it's always nice to have just in case.
You can click here to learn more about Ethereum's data structure, but again it's not really needed for using Dune.
Centralised exchanges trading data
Token volume is great, but more often than not you want to know the USD value of smart contract activity.
You can easily get and join that information with onchain data using the data we pull from the coincap API. See how to use it below.
prices.usd
- assets on EthereumNote that
WETH
can be used for ETH price.prices.layer_1usd
- native layer 1 assetsPrice is the volume-weighted price based on real-time market data every minute, translated to USD.
The data is fetched from the Coinpaprika API.
👨🏫 Tips for querying the data
You can interact with the data tables through our interface at duneanalytics.com.
To create a new query you simply click
New Query
in the top right cornerOn your left you can select which database you want to use in the dropdown list and then see the data tables in the window. Just search for the project you are interested in working with.
Use view abstractions and tables
The easiest way to do great analysis with Dune Analytics is to use prepared views named
namespace.view_
or abstraction tables likedex.trades
. All the view tables are cleaned and contains data and metadata (like human readable token symbols) that make them very straight forward to query.Using Inline Ethereum addresses
In Dune Ethereum addresses are stored as postgres bytearrays which are encoded with the
\x
prefix. This differs from the customary0x
prefix. If you'd like to use an inline address, say to filter for a given token, you would dowhich is simply short for
Quote camel case column and table names
Column and table names are mostly taken directly from smart contract ABIs, with no modification. Since most smart contracts are written in Solidity, and written with a camelCased naming convention, so is many of Dune's table and column names. Postgres requires you to quote columns and tablenames that are case sensitive:
In Postgres, double quotes are reserved for tables and columns, whereas single quotes are reserved for values:
Schemas are always lowercase in Dune.
Remove decimals
Ether transfers and most ERC-20 tokens have 18 decimal places. To get a more human readable number you need to remove all the decimals. The table
erc20.tokens
gives you contract address, symbol and number of decimals for popular tokens. Token value transfers are then divided by 10 to the power of decimals from this table:transfer_value / 10^erc20.tokens.decimals
Use
date_trunc
to get timeWe've added
evt_block_time
to decoded event tables for your convenience. A neat way to use it is with thedate_trunc
function like thisHere you can use minute, day, week, month.
How to get USD price
To get the USD volume of onchain activity you typically want to join the smart contract event you are looking at with the usd price and join on minute. Also make sure that asset matches asset.
Then you can simply multiply the value or amount from the smart contract event with the usd price in your
SELECT
statement:* p.price
.Token symbols
You often want to group your results by token address. For instance you want to see volume on a DEX grouped by token. However, a big list of token addresses are abstract and hard to digest.
Therefore you often want to use the token symbol instead. Simply join the table
erc20.tokens
with your event table where asset = token address. You then select symbol in your select statement instead of token address.NB The
erc20.tokens
table cointains a selection of popular tokens. If you are working with more obscure tokens you should be careful with joining with this table because tokens that are not in the coincap table might be excluded from your results.Filter queries and dashboards with parameters
Parameters can turn your query or dashboard into an app for blockchain data.
Click
Add parameter
in the bottom right of the SQL editor on the query editor pageDouble curly bracets will appear in your query
{{}}
. Inside these you put the name of your paramter liketoken symbol
orholder address
.Note that you need to put single quotes if you want to use the parameter in your query
WHERE token = '{{token symbol}}'
.To save the user from having to put in
\x
for the address a useful formatting of addresses is this one:This let's a user of your query simply paste in
0xc00e94cb662c3520282e6f5717214004a7f26888
instead of\xc00e94cb662c3520282e6f5717214004a7f26888
when they filter.🚨 Our docs have moved to docs.dune.xyz 🚨
🏷 Address Labels
Have you ever made a query on Dune where you get a list of addresses, only to stop and wonder what's behind these beautiful, random hexadecimal encoded strings? So have we.
Address labels is a new feature on Dune where you as a user can add, update and query labels for any address. All for free!
🪧 What is a label?
A label is a piece of metadata about an address, a tag or metadata if you will. It comes in the form of a key-value pair. The key is the label type, and the value the label name.
Browse addresses and and labels at the labels page.
🖼 What labels looks like
Check out this dashboard for examples on what can be created with labels.
Address label examples
The address 0xD551234Ae421e3BCBA99A0Da6d736074f22192FF can be labeled
Because the address is controlled by the exchange Binance.
The address 0xe65040f61701940b62e18da7a53126a58525588b can be labeled
Because the address in the past interacted with Uniswap.
You are free to come up with both new types and label names, as labels on Dune are open ended and crowdsourced 🎉.
📥 Adding labels
There are two ways to add labels:
1. Directly to an address via our labels page
Good for specific labels like "this is a binance wallet"
2. Via a Dune query
Use Dune queries to label addresses 🤯 A very powerful and scalable way to add labels like "all these addresses used Uniswap", and much much more.
Please see our Github for examples of labels created with queries and PR in your own!
Examples of what you can do:
You could also do more novel and involved things around user patterns like who did arbitrage trades or profited from flash loans and so much more.
Note that there might be a few minutes delay from adding the label on duneanalytics.com until you can query it in SQL.
🗄 The labels table
Labels are stored in the new
labels.labels
table which has the following schema:🧑🔧 Using labels
Note that this table holds multiple rows per address, and therefore joins against it can be tricky to get right. For that reason we've made the convenient function:
labels.get(address bytea, type text default null) RETURNS text[]
which we anticipate will be the primary way to use labels. See examples below.
Typically if you do a query that returns
address
you can uselabels.get(address)
to get all labels for that address independent of label type. If you want to see labels of the typeowner
you can dolabels.get(address, 'owner')
. You can also pass this function several label types you want included like:labels.get(address, 'owner', 'project')
.We've also added the function
labels.url(address bytea)
. Pass that function an address from your query and your results table will contain a clickable link to for instance:https://duneanalytics.com/ethereum/address/0xD551234Ae421e3BCBA99A0Da6d736074f22192FF
📜 Usecase: I want to display labels for a list of addresses
Say you're looking at the top 10 traders of DAI across all dexes last 24 hours:
If you want to have labels for these addresses simply alter the
trader_a
column tolabels.get(trader_a)
.Now you've replaced the addresses with lists of all labels for trader_a. Sometimes you're only interested in a subset of labels:
labels.get
accepts an optional list of type names which filter the type of labels you get. Say you're only interested in 'activity' labels:Of course you can also show the address, and filter for multiple label types
You can also use
labels.url
to make the addresses clickable:This way people who look at your dashboard can easily contribute even better labels to it!
🧼 Usecase: I want to filter my query by labels that exist.
In this usecase you wouldn't want to use
labels.get
, because it can be slow to operate with. Instead you'll use the fantasticEXISTS
function in SQL.As an example: you're querying Uniswap, but are interested in the behavior of users who have traded previously on 1inch. Here's how you'd go about that:
The above query will give you 10 address that has swapped on Uniswap and traded on 1inch.
Of course, you can use the two patterns in conjunction! If you are interested for labels on those addresses, go ahead and use
labels.get
in addition to theWHERE EXISTS
pattern:There you have it: you see addresses that traded on both Uniswap and 1inch and all associated address labels.
🧐 Understanding data decoding in Dune Analytics
This section contains a quick primer on how you can explore what decoded data we have and the methods we use to decode the data.
In Dune, there are tables for each event and function defined in the smart contract ABI. Subsequently, every event or function call on that contract is decoded and inserted as rows into these tables.
The tables are named accordingly
events:
projectname."contractName_evt_eventName"
function calls:
projectname."contractName_call_eventName"
As an example, decoded data for the
AddLiquidity
-event andaddLiquidity
-function of the uniswap exchange contract are found in tablesuniswap."Exchange_evt_AddLiquidity"
anduniswap."Exchange_call_addLiquidity"
.Using the event tables is usually sufficient, but in some cases you will want to use the
call
tables. For instance Maker DAO which don't give you too many events you can use tables likemaker.SaiTub_call_draw
.What contracts have decoded data?
Decoded data
By querying
ethereum.contracts
, you can get an overview over which contracts are tracked by the Dune backend. The columns areAbstractions and views
On top of the decoded tables we have a growing number of views that make it even easier to work with the data.
Views are named
namespace.view_event
for instance. In general you can search forview
in the table list to find the views we have.A few handy queries to explore decoded tables
See all projects we have decoded data for
Do we have decoded data for a specific contract?
Contracts that are "interface"-decoded
If you are working with a an event or call table directly you can see if there are several instances of that contract with
Scalable decoding across contracts
Many dApps have numerous smart contracts that are more or less similar, we have two main ways of handling this in a scalable way:
Contracts with the same bytecode
Dune can dynamically add contracts to track by comparing the bytecode of deployed contracts to known bytecodes. If a known contract is "dynamic", events and calls to a newly deployed contract with matching bytecode will find it's way into the same tables as were defined by the base contract. Essentially this covers all factory-pattern contract architectures. As a result,
SELECT
-ing from a single table might yield data from multiple contracts. In decoded tables, the columncontract_address
tells you which smart contract the event or call is on. If you want to look at only a single contract you can filter by its address.For example:
Will give you all the unique Uniswap exchanges with a Token Purchase event.
Interfaces
When we're interested in a subset of events fired regardless of the origin contract, Dune uses interface-decoding. Notable examples include erc20 and erc721 transfer events. This method is reserved for special cases.
How Dune handles Proxy contracts
Sometimes users interact with dApps through proxy contracts. The proxy contract throws the event, but there's an underlying contract that contains and performs the action. In those cases, we apply the ABI of the proxied contract (sometimes called "master copy") to the proxy contract address. We also usually apply the name of the proxied contract to the relevant table.
📬 Get any smart contract decoded
We have decoded data for the most popular smart contract projects. Head to duneanalytics.com/decode if you have a request for decoding of data.
👩🏭 Change log
March 2021 - Dune version 2 is live!
August 2020 - USD prices for more assets, token decimals on
prices.usd
tableMarch 2020 - block_time denormalization, traces.success and more
January 2020 - ERC20 transfer table, Fallback decoding and more
October 2019 - New data structure
👉 Some sample queries
Growth rate
Assuming you have a query with a count of some event grouped by time (month for instance) you can add this snippet to you
select
statement to get growth rate.Multiply the number by 100 to get percentage.
Users and amount over a trailing period
Filter query by an address in the interface
If you use
{{}}
in a query an input field in the UI will appear and anyone looking at the query can easily input info in that field that will go into the query.This is very useful when filtering for custom atributes like an Ethereum address or a token address.
When you query in Dune you use
\x...
while people commonly use0x...
(see more details here).Using the below snippet will allow users to past addresses in the regular
0x...
format and then convert it to\x...
that will work in a query.Here's an example of this being applied in a query.
Circulating supply over time of a token with mint/burn functions
Circulating supply over time with mint/burn from
0x000...
addressUSD value of token utilised for an event
USD trading volume per token over time
USD price for a token from Uniswap
The most common and easiest way to get token USD prices on Dune Analytics is with the
prices.usd
table. However, this data is fetched from centralised exchanges so for a long tail of tokens the best approach is to get prices from Uniswap.This query uses WETH pairs, which is used to map to USD price. The query can be modified to work with any token that has a price in
prices.usd
You can find this query on Dune here.
Token (and USD value) per token over time for an address
Note that this query can get very heavy when there are many tokens and transfers over a long period of time.
🤕 Known issues
Function overloading
We have a known issue with function overloading. There are a few cases where smart contract developers use function overloading, i.e. specify two functions with the same name but different parameters. In these cases, we will currently only have one of the implementations in our database. We’re working on a fix for this. One known case is the two approve implementations in the SAI contract.