Sub topic 1
How on-chain data is structured: blocks, transactions, logs and traces
Prerequisites
This chapter assumes you know what a blockchain, address, smart contract, transaction, and block are. You should also understand that smart contracts can change state when a transaction calls them. Basic SQL knowledge will help when you later query this data in Dune.
On-chain data is not stored as a ready-made table such as “daily swap volume.” A blockchain records lower-level events. Analytics platforms organize those records into tables and add decoded or derived fields.
The block is the outer container
A block is a batch of data accepted by a blockchain. Blocks normally contain:
- A block number or height
- A block hash
- A timestamp
- The hash of the previous block
- A list of transactions
- Consensus and fee metadata
The block timestamp is commonly used for daily or hourly analysis. It represents the time associated with the block, not necessarily the exact time when a user clicked a button.
A blockchain can temporarily have competing versions of recent history. This is called a reorganization, or reorg. Analytics systems may revise recent records after the network selects a different chain. For historical analysis, wait for enough confirmations when the chain's finality model requires it.
Transactions describe requested actions
A transaction is a signed request submitted by an account. It may transfer the native asset, call a contract, deploy a contract, or fail during execution.
Typical transaction fields include:
- The sender and recipient addresses
- The transaction hash
- The transaction value
- Gas or fee fields
- Input data
- Success or failure status
- The block containing the transaction
A successful transaction does not always mean that the intended business action happened. A contract call can execute successfully while a particular swap, transfer, or internal operation is absent. To understand what happened, inspect the emitted logs and execution traces.
Logs record emitted events
A smart contract can emit an event while it runs. The blockchain stores the event as a log. Logs usually contain:
- The emitting contract address
- An event signature
- Indexed arguments, called topics
- Non-indexed event data
- The transaction hash and log position
- Block number and timestamp
For an ERC-20 token, a transfer often appears as a Transfer event with a sender, recipient, and raw token amount. Dune can decode known event signatures into readable columns. A decoded table is easier to query than raw hexadecimal data.
The same transaction can emit many logs. A decentralized exchange swap might emit token transfer events, pool-specific swap events, fee events, and approval-related events. Counting every log as a separate user action can therefore overstate activity.
Traces reveal internal execution
A trace describes calls made during transaction execution. These calls can be direct calls from the user to a contract or internal calls between contracts. Traces are useful for finding native-asset movements that do not appear as top-level transactions.
For example, a user may call a router contract. The router calls a liquidity pool, and the pool sends native currency to another contract. The transaction table shows the user's original request, while traces expose the nested calls.
| Record | Main question answered | Common use |
|---|---|---|
| Block | When and where was data included? | Time series and chain ordering |
| Transaction | What request did an account submit? | Users, fees, success rates |
| Log | What event did a contract emit? | Token transfers and protocol actions |
| Trace | What calls occurred during execution? | Internal calls and native-asset flows |
How the records fit together
A practical analysis usually follows the identifiers connecting these layers:
- Start with a block date or timestamp.
- Find transactions included in that time range.
- Use the transaction hash to locate related logs and traces.
- Filter by contract address or event type.
- Aggregate the decoded values into a metric.
When you query Dune, choose the record layer that matches the question. Use transactions for submitted requests, decoded logs for token or protocol events, and traces for internal calls. Curated tables may combine these layers, but you still need to understand their source records to avoid double counting.
Exercise
A transaction calls a DEX router and produces four ERC-20 Transfer logs plus one pool Swap log. Which record should you count as the swap, and why?
Show answer
Count the decoded pool Swap event when measuring swaps. The Transfer logs describe token movements caused by the swap, so counting all five records as swaps would double count the action.