Sub topic 1
How Ledger Design Shapes What You Can Measure
Prerequisites
This chapter assumes you know what a blockchain, wallet, and transaction are. You should be able to read simple Python, including sets, dictionaries, and loops. You should also know basic statistics such as counts, percentiles, and distributions.
Account-based and UTXO ledgers
An account-based ledger, such as Ethereum's, stores a balance for each address. A transfer debits one account and credits another, so "balance of address X" is a direct lookup.
A UTXO ledger, such as Bitcoin's, stores unspent transaction outputs (UTXOs), which are discrete coins locked to addresses. A transaction consumes old outputs and creates new ones. An address's balance is the sum of its unspent outputs.
This difference changes your metrics. In a UTXO ledger, one transaction can return change to a new address. That address appears in the data as a receiver but may not be an economic actor. Account-based ledgers avoid this issue but have their own quirks, such as contract calls that move value between addresses without a clear sender.
Addresses are not people
An address is a string derived from a public key. One person can control many addresses, and an exchange can control millions.
Clustering is a heuristic that groups addresses likely controlled by the same entity. Common methods use shared inputs in a UTXO transaction or repeated deposit patterns. Clustering produces probable groups, so labels contain errors.
Where on-chain data comes from
- A full node validates and stores the chain. Querying it gives exact data but requires storage and an RPC interface.
- An indexer reads blocks and writes queryable tables, such as transfers per address per day.
- An analytics API provides labeled entities and precomputed metrics. Labels and definitions differ between providers.
Active addresses: definition and computation
An active address is an address that sends or receives at least once in a time window, usually one UTC day. The following script counts active addresses per day from transfer records.
from collections import defaultdict
from datetime import datetime, timezone
transfers = [
{"ts": 1700000000, "from": "0xa", "to": "0xb", "value": 5},
{"ts": 1700003600, "from": "0xb", "to": "0xc", "value": 2},
{"ts": 1700090000, "from": "0xa", "to": "0xc", "value": 1},
]
def daily_active_addresses(transfers):
days = defaultdict(set)
for t in transfers:
day = datetime.fromtimestamp(t["ts"], tz=timezone.utc).date()
days[day].add(t["from"])
days[day].add(t["to"])
return {day: len(addrs) for day, addrs in sorted(days.items())}
print(daily_active_addresses(transfers))The output is {datetime.date(2023, 11, 14): 3, datetime.date(2023, 11, 15): 2}.
Several factors distort this count. Change outputs inflate it on UTXO chains. One entity using many addresses inflates it. Exchanges rotating deposit addresses inflate it too. Time zone choice shifts which transfers fall on which day.
Exercise
Exercise
The function stores senders and receivers in a set for each day. Why a set instead of a counter?
Show answer
A set keeps each address once per day, so an address that transacts many times still counts as one active address.