Sub topic 3
Where On-Chain Data Comes From
Prerequisites and the basic data path
This chapter assumes you understand blocks, wallets, transactions, and simple Python code. It also assumes you know that an address is a ledger identifier, not necessarily a person or organization.
On-chain metrics begin with ledger records. A blockchain stores blocks, transactions, state changes, and sometimes event logs. Analysts transform these records into tables such as:
| Raw record | Common analytical use |
|---|---|
| Transaction sender and receiver | Active addresses and transfer counts |
| Token transfer event | Token volume and exchange flows |
| Current account balance | Holder distribution |
| Block timestamp | Daily or hourly time windows |
The general path is:
A node is software that stores and validates blockchain data. You can query a node directly, usually through a remote procedure call (RPC), which is a request for a specific blockchain object or operation. For example, an RPC request might ask for a block, a transaction receipt, or an account balance.
A node is close to the source, but it is not automatically an analysis system. Many metrics require scanning thousands or millions of blocks, decoding token events, joining labels, and removing duplicates. Those tasks are usually handled by an indexer.
Nodes: direct access to the ledger
A full node verifies the chain and keeps enough data to answer normal queries. Some networks also support archive nodes, which retain historical state needed for questions such as “What was this account’s balance at an earlier block?”
A direct node query is useful when you need:
- The latest confirmed data.
- Exact transaction or block details.
- Independent verification of a result from another provider.
- Data that an indexer does not expose.
It is less convenient for historical analysis. You may need to determine the block range, handle pagination, decode binary or hexadecimal fields, and retry requests. Different networks also expose different RPC methods and data models.
A minimal Python example can extract transfers from a response that has already been returned by an RPC or indexer:
import json
response = {
"result": {
"transfers": [
{"block": 100, "from": "0xa", "to": "0xb", "value": "5"},
{"block": 101, "from": "0xb", "to": "0xc", "value": "2"},
]
}
}
def read_transfers(payload):
return [
{
"block": item["block"],
"from": item["from"].lower(),
"to": item["to"].lower(),
"value": int(item["value"]),
}
for item in payload["result"]["transfers"]
]
print(json.dumps(read_transfers(response), indent=2))This code normalizes addresses to lowercase and converts values from strings to integers. Real systems must also account for token decimals, contract-specific rules, and malformed records.
Indexers and analytics APIs
An indexer reads blockchain data and creates query-friendly tables. It may store one row per transaction, token transfer, contract event, address balance, or block. Indexers can make historical queries much faster than scanning a node yourself.
An analytics API is a service that exposes prepared data through SQL, HTTP endpoints, dashboards, or downloadable files. It may add labels such as “exchange,” “stablecoin,” or “bridge.” These labels are useful, but they are interpretations rather than facts directly written into the ledger.
The main trade-offs are:
| Source | Strength | Risk or cost |
|---|---|---|
| Direct node | Close to validated source | Slow historical queries and technical setup |
| Indexer | Fast structured queries | Coverage, decoding, and reorganization issues |
| Analytics API | Convenient labels and ready-made metrics | Opaque definitions, limits, and provider dependence |
Checks before calculating a metric
Before computing active addresses, transfer volume, or holder concentration, record the data definition. At minimum, specify:
- The network and asset.
- The block range or timestamp range.
- Whether native-asset transfers, token transfers, contract calls, or all of them are included.
- How failed transactions are handled.
- How addresses are normalized.
- Whether known exchange, bridge, burn, or treasury addresses are excluded.
- Whether values are measured in base units or converted using decimals.
A block timestamp is not always the same as the time a user initiated an action. Blocks can arrive at uneven intervals, and indexing providers may apply different confirmation delays. Use one time zone, usually UTC, and state whether the end of a window is inclusive.
Reorganizations, missing data, and reproducibility
A chain reorganization, or reorg, occurs when the network replaces a previously observed branch with another valid branch. Recent data can therefore change. Analysts often wait for a chosen number of confirmations before treating records as final.
Keep the provider name, query text, extraction time, block range, and software version with the result. When possible, compare a sample against a second source. A metric is easier to audit when another analyst can reproduce the same input and rules.
Exercise
You need exchange netflow for the previous calendar day. Which details should you define before querying the data?
Show answer
Define the network and asset, UTC start and end times, confirmation policy, transfer types, token-decimal conversion, exchange-address labels, and how internal exchange-to-exchange transfers and failed transactions are treated.