Sub topic 4
Raw, decoded and curated tables
Dune stores the same chain activity at three levels of processing. Choosing the right level decides how much SQL you write, how fast the query runs, and how far you can trust the result. This chapter assumes you can read a basic DuneSQL query and know what a transaction, a log and an ERC-20 Transfer event are. The earlier chapters on the on-chain data model and DuneSQL basics cover both.
The three layers
Each layer is built from the one before it.
| Layer | Example tables | What a row is | Typical amounts | Who maintains it |
|---|---|---|---|---|
| Raw | `ethereum.transactions`, `ethereum.logs`, `ethereum.traces` | A transaction, log or trace exactly as the node returned it | Unscaled integers, bytes | Dune ingestion |
| Decoded | `erc20_ethereum.evt_Transfer`, `uniswap_v3_ethereum.Factory_evt_PoolCreated` | One event or function call, with named typed columns | Unscaled integers (`value`) | Automatic from a contract's ABI |
| Curated | `dex.trades`, `tokens.erc20`, `prices.usd` | A business-level record, such as one swap | Scaled amounts, often with USD | Community models in the Spellbook repository |
The arrows in the diagram also show that you can enter at any layer. Moving up gives you convenience. Moving down gives you coverage and control.
Raw tables
Raw tables mirror what the chain contains. The main ones for Ethereum are:
ethereum.blocks: one row per block.ethereum.transactions: one row per transaction, with sender, recipient, value in wei and gas fields.ethereum.logs: one row per emitted event, withcontract_address,topic0totopic3, and adatablob.ethereum.traces: one row per internal call, which is how you see ETH moved by contracts rather than by users directly.
Other chains have the same tables under their own schema, for example arbitrum.logs.
In a log, topic0 is the hash of the event signature. For ERC-20 Transfer(address,address,uint256) it is 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef. The indexed arguments from and to sit in topic1 and topic2, each padded to 32 bytes. The non-indexed value sits in data.
This query computes USDC transfers straight from raw logs:
SELECT
block_date,
COUNT(*) AS transfer_logs,
SUM(CAST(bytearray_to_uint256(data) AS double) / 1e6) AS usdc_transferred
FROM ethereum.logs
WHERE contract_address = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
AND topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
AND block_date >= current_date - INTERVAL '7' DAY
GROUP BY 1
ORDER BY 1You must do the decoding yourself. bytearray_to_uint256(data) turns the 32-byte blob into a number. To get an address out of topic1, take the last 20 bytes with bytearray_substring(topic1, 13, 20). Do not use bytearray_ltrim for this, because it strips every leading zero byte and would corrupt addresses that begin with 0x00.
Use raw tables when:
- the contract has no decoded table, for example it is unverified or not yet submitted;
- you need an event across many contracts, such as every
Transferlog regardless of token; - you are debugging a number from a higher layer.
The ERC-721 trap
ERC-721 NFTs use the same Transfer signature as ERC-20, so they share topic0. The difference is that the token ID is indexed, so NFT transfers have four topics, while ERC-20 transfers have three. If you filter raw logs only on topic0 without a contract address, you mix both standards. Add AND topic3 IS NULL to keep ERC-20 only.
Decoded tables
Dune takes a contract's ABI (its machine-readable interface description) and creates a typed table for every event and function in it. You get named columns instead of byte offsets.
Naming follows a pattern:
- Events:
<project>_<chain>.<Contract>_evt_<Event> - Function calls:
<project>_<chain>.<Contract>_call_<Function> - Generic standards:
erc20_<chain>.evt_Transfer
Event tables carry the event's own arguments plus metadata: contract_address, evt_tx_hash, evt_index, evt_block_time, evt_block_number and the partition column evt_block_date. Call tables use the call_ prefix on the same fields and add call_success.
The raw-log query above becomes much shorter:
SELECT
date_trunc('day', evt_block_time) AS day,
SUM(CAST(value AS double) / 1e6) AS usdc_transferred
FROM erc20_ethereum.evt_Transfer
WHERE contract_address = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
AND evt_block_date >= current_date - INTERVAL '7' DAY
GROUP BY 1
ORDER BY 1Note that from and to are SQL keywords, so quote them as "from" and "to" when you select them.
Decoded tables are still unscaled. value for USDC is a count of millionths of a dollar, so you divide by 1e6. Nothing in the decoded layer knows the token's decimals.
Limits of decoding
- Coverage depends on submission. A contract only gets tables once its ABI is known to Dune. A brand-new protocol may have none.
- Factory-created contracts. Protocols such as Uniswap deploy a new contract per pool. Decoding each pool requires the factory to be mapped, otherwise pool events are missing.
- Proxies. Events are emitted from the proxy address but defined in the implementation's ABI. Decoding must use the implementation ABI. After an upgrade, new events may appear later than the contract does.
- Call tables miss internal calls. A function invoked by another contract still appears if it was traced, but a failed call has
call_success = false. Filter on that column when you want only successful calls.
Curated tables
Curated tables are produced by SQL models in Dune's Spellbook, a public repository. They normalize many sources into one schema and add token symbols, decimals and USD prices.
dex.trades is the standard example. It unions swaps from many exchanges across many chains into one row per swap leg, with columns such as blockchain, project, version, block_date, token_bought_symbol, token_sold_symbol, token_bought_amount, amount_usd and tx_hash.
SELECT
block_date,
SUM(amount_usd) AS volume_usd
FROM dex.trades
WHERE blockchain = 'ethereum'
AND block_date >= current_date - INTERVAL '30' DAY
GROUP BY 1
ORDER BY 1The same question at the decoded level would require unioning a swap event table for every exchange, converting each one's token amounts by its own decimals, and joining prices. Curated tables do that work for you.
Other curated tables you will meet often:
tokens.erc20: contract address, symbol and decimals for known tokens.prices.usd: minute-level token prices.nft.trades: the NFT equivalent ofdex.trades.labels.*: address labels such as exchange wallets.
What curation costs you
Curation means someone else made decisions for you, and those decisions can differ from yours:
- Coverage. A DEX that no model includes is absent. Totals are only as complete as the model list.
- Null or approximate USD.
amount_usdis null when the model has no price for either token. ASUMskips nulls silently, so volume is understated for long-tail tokens. - Granularity. One user swap routed through three pools produces three rows. Summing
amount_usdover all rows can count the same capital more than once. A separate aggregator table exists for router-level analysis. - Model changes. Models are updated, so the same query can return slightly different numbers weeks later.
Choosing a layer
Start at the highest layer that answers the question, then drop down only when you need to.
| Question | Best layer | Reason |
|---|---|---|
| Daily DEX volume on Ethereum | Curated (`dex.trades`) | Many exchanges, USD already attached |
| Transfers of one specific token | Decoded (`erc20_ethereum.evt_Transfer`) | Typed columns, partition filter, small scan |
| Pool creations for one factory | Decoded (`..._evt_PoolCreated`) | Event has named arguments |
| Events from an undecoded contract | Raw (`ethereum.logs`) | No other option |
| ETH sent inside contract calls | Raw (`ethereum.traces`) | Only traces expose internal transfers |
| Explaining why two numbers differ | Raw plus decoded | Rebuild the figure from the chain |
Tables in any layer are large, so always filter on the partition date column: block_date for raw and curated tables, evt_block_date for decoded event tables. This applies the efficiency rules from the next chapter.
Common errors
- Treating decoded
valueas dollars. It is a raw integer. Divide by10^decimals. - Using
evt_block_timealone for pruning. Filter on the date column so Dune can skip partitions. - Forgetting the contract filter on
erc20_ethereum.evt_Transfer. Withoutcontract_address, you sum every token with different decimals and different values. - Assuming a missing decoded table means no activity. It may only mean the contract is not decoded. Check raw logs.
- Trusting
amount_usdtotals without checking nulls. Count rows whereamount_usd IS NULLto see how much is unpriced.
Exercise
You want total USDC transferred yesterday. Name two tables that can answer it, and state one extra step the raw table needs that the decoded table does not.
Show answer
Use erc20_ethereum.evt_Transfer (decoded) or ethereum.logs (raw), both filtered to the USDC contract address. The raw table requires filtering on topic0 (the Transfer signature hash) and decoding the amount from data with bytearray_to_uint256. In both cases you still divide by 1e6, because USDC has 6 decimals.
Exercise
A colleague reports that dex.trades shows $2.0B volume for a day, but summing swap events from one exchange's decoded tables gives $2.3B. List two reasons the curated number could be lower.
Show answer
The curated model may leave out part of that exchange (for example a newer version or a factory-created pool), and rows with null amount_usd are skipped by SUM when no price exists for a token. Different price sources or timestamps between your join and the model can also change USD totals.