Sub topic 4
Where the data comes from: nodes, explorers, and analytics APIs
This chapter assumes you know what a blockchain, an address, and a transaction are. It also assumes you can read basic Python and have met the UTXO and account models in the earlier chapter. Every exchange-flow or whale number in this tutorial comes from one of three places: a node you run, a block explorer, or an analytics API. Each gives you a different mix of raw access, convenience, and trust, so the source you pick shapes what your numbers can mean.
The three layers of data access
Think of the sources as layers. Each layer sits on top of the one below it.
- Nodes hold the raw chain. They validate blocks and serve transactions, receipts, and (on some configurations) historical state.
- Explorers and indexers read from nodes, decode the data, and store it in a searchable database. Etherscan and mempool.space are examples.
- Analytics APIs add derived data on top of an index. This includes entity labels, aggregated exchange balances, and precomputed netflow. Providers such as Glassnode, Nansen, Arkham, and Dune (for community-written queries) work at this layer.
Reading from a higher layer saves work but means you trust more steps that you cannot inspect. Reading from a lower layer costs more work but gives you raw facts, and you apply the interpretation yourself.
Running or renting a node
A full node downloads and validates every block. It exposes an interface for queries. On Ethereum this is JSON-RPC over HTTP or WebSocket. Bitcoin Core offers a similar RPC interface.
Node types that matter for tracking
| Node type | What it keeps | What you can do | Typical gotcha |
|---|---|---|---|
| Full node | All blocks, receipts, and recent state | Read blocks, transactions, and logs; check current balances | Old balances at past blocks are usually unavailable |
| Archive node | Full node data plus state at every block | Query a balance at any past block | Storage runs to many terabytes on Ethereum |
| Bitcoin Core with `txindex=1` | Full chain plus an index of all transactions | Look up any transaction by its hash | Without the index, only wallet and recent lookups work |
Most flow tracking needs only blocks, transactions, and logs, so a full node is enough. Balance snapshots at past dates, such as a holder's balance on a given day last year, need an archive node or an indexer that already did that work.
Renting access
Running a node takes disk, bandwidth, and maintenance. Many teams rent access from a hosted RPC provider instead. This is faster to set up. It brings rate limits, per-request pricing, and a limit on how many blocks one eth_getLogs call can span. Many providers cap the block range or the number of results, so a wide query often fails and must be split into smaller ranges.
What a node does not give you
A node reports facts about transfers. It does not tell you who owns an address. It also does not decode every kind of movement for you:
- Token transfers appear as event logs, as covered in the previous chapter on token transfers.
- Native ETH sent from one contract to another, called an internal transaction, produces no log. You need a trace method such as
debug_traceTransactionortrace_block. These are not available on every node or provider. - Bitcoin transactions list inputs and outputs, not "from" and "to". Turning them into labeled flows requires extra logic from the address-clustering chapter.
Fetching token transfers from a node
This script uses only the standard library. It queries ERC-20 Transfer events for a token over a block range and converts them into simple dictionaries. Set ETH_RPC_URL to your own node or provider URL first.
import json
import os
import urllib.request
RPC_URL = os.environ["ETH_RPC_URL"]
TRANSFER_TOPIC = (
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
)
def rpc(method, params):
body = json.dumps(
{"jsonrpc": "2.0", "id": 1, "method": method, "params": params}
).encode()
req = urllib.request.Request(
RPC_URL, data=body, headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req, timeout=30) as resp:
payload = json.load(resp)
if "error" in payload:
raise RuntimeError(payload["error"])
return payload["result"]
def topic_to_address(topic):
# An indexed address is a 32-byte topic; the address is the last 20 bytes.
return "0x" + topic[-40:]
def fetch_transfers(token, start_block, end_block, decimals):
logs = rpc(
"eth_getLogs",
[
{
"fromBlock": hex(start_block),
"toBlock": hex(end_block),
"address": token,
"topics": [TRANSFER_TOPIC],
}
],
)
transfers = []
for log in logs:
# ERC-721 uses the same event signature with 4 topics; skip those.
if len(log["topics"]) != 3 or log["data"] in ("0x", ""):
continue
transfers.append(
{
"block": int(log["blockNumber"], 16),
"tx": log["transactionHash"],
"from": topic_to_address(log["topics"][1]),
"to": topic_to_address(log["topics"][2]),
"amount": int(log["data"], 16) / 10**decimals,
}
)
return transfers
def fetch_in_chunks(token, start_block, end_block, decimals, step=500):
result = []
for lo in range(start_block, end_block + 1, step):
hi = min(lo + step - 1, end_block)
result.extend(fetch_transfers(token, lo, hi, decimals))
return result
if __name__ == "__main__":
# Replace with a real token contract address and the token's decimals.
token = "0x0000000000000000000000000000000000000000"
for t in fetch_in_chunks(token, 17_000_000, 17_000_020, 18):
print(t)A few details in this code matter:
- Amounts on chain are integers in the token's smallest unit. You must divide by
10**decimals. USDT and USDC use 6 decimals, and many other tokens use 18. Using the wrong value silently scales every number. - The result has a block number, not a day. The flow function from the exchange-flow chapter expects a
dayfield. You get it by reading each block's timestamp witheth_getBlockByNumberand converting it to a UTC date. Cache these timestamps, because many logs share a block. - Addresses are lowercase hex here. Make sure your label table uses the same form, because Ethereum checksum casing differs between sources and a case mismatch quietly drops matches.
Block explorers
An explorer is an indexer with a web interface and, usually, an API. Etherscan-style APIs let you ask "list the token transfers for this address" without scanning blocks yourself. Explorers also publish labels for well-known addresses, such as "Binance 14".
Explorers suit three jobs well:
- Checking a single transaction or address by hand.
- Verifying a number from your own pipeline.
- Getting a first set of labels for large exchanges.
They are a weaker base for a production pipeline. Free tiers have low rate limits. Results per request are capped, so a busy exchange address needs pagination. Their label sets are not documented as a dataset, and you have little visibility into how a label was assigned.
Analytics APIs
Analytics providers sell what the lower layers do not provide: entity labels, clustered wallets, and ready-made series such as exchange netflow or top-holder share. They differ in three ways that affect your results.
| Question to ask | Why it matters |
|---|---|
| How are entities defined? | One provider may merge an exchange's hot and cold wallets into one entity. Another may list them separately, which changes balances. |
| Which chains and tokens are covered? | A missing token or chain produces a flow of zero, which looks like a result. |
| How often is data updated, and is it revised? | Provider series are often corrected later, so a value you read today may change. |
Their strength is speed and coverage. Their weakness is that the labeling method is usually a black box. You cannot rerun it, and two providers can disagree on the same exchange. Later chapters cover label quality in detail.
Query platforms
Platforms such as Dune and Flipside sit between raw nodes and closed analytics. They keep decoded chain data in SQL tables, and you write queries over them. This approach gives you the data layer and the logic in a form you can inspect and share. The cost is that you depend on their indexing schedule and on query limits.
Choosing a source
Pick the source from the question you are trying to answer, not from habit.
- A one-off check on an address or transaction. Use an explorer.
- A research question over history, such as flows into labeled exchanges over a year. Use a SQL platform or an indexed dataset, then verify a sample against raw data.
- A live monitor that alerts on large transfers. Use a node or a hosted RPC provider with WebSocket subscriptions, since you want low delay and control of the thresholds.
- Labels. Combine at least two label sources and keep a record of which one supplied each label. Treat any single provider's labels as a claim, not as truth.
A good habit is to reconcile across layers. Pick a few transactions, then check that your node-based numbers match an explorer and, where possible, an analytics series. A mismatch tells you where to look: a missing decimal, a skipped internal transfer, an unlabeled address, or a reorg.
Common errors with data sources
- Silent truncation. An API returns the first N results and no error. Check result counts against the cap and paginate.
- Mixed block and time ranges. Providers describe ranges in blocks, in timestamps, or in "days". Convert everything to UTC dates early and keep the block number as the source of truth.
- Double counting. One transaction can emit several
Transferlogs, such as a swap routed through several pools. Summing every log can count the same value more than once. Always inspect the multi-hop case before trusting totals. - Unit confusion. Wei, gwei, satoshi, and token decimals all look like plain integers. Store the raw integer and the decimals together.
- Untracked provenance. Store the source and fetch time with each dataset. Without that, you cannot explain why a number changed.
Exercise
You run the script above for a token with 6 decimals but pass decimals=18. What happens to the amounts, and how could you catch the mistake?
Show answer
Every amount is divided by 1018 instead of 106, so each value is 10**12 times too small, and all results look close to zero without any error being raised. You can catch it by checking one transfer against an explorer's displayed amount, or by reading the token's decimals() function from the contract instead of passing a guess.
Exercise
Your pipeline measures daily netflow for a native-ETH exchange wallet using only eth_getLogs. Why would the result be wrong, and what do you need instead?
Show answer
Native ETH moves are not emitted as Transfer event logs. Plain ETH transfers appear in transaction values, and transfers made by contracts appear only in traces. You need to read transaction values from blocks and use a trace method (such as trace_block or debug_traceTransaction) to capture internal transfers.