#!/usr/bin/env python3 """How many of the first 2,016 coinbase outputs (Jan 2009, all P2PK = public key on chain) were ever spent? Python 3 stdlib. Reads first-2016.csv (height,txid,vout,pubkey; e.g. from the reproducible bundle in the findsatoshi.work Genesis Keyring case, sha256 e24742a6...cb05) and asks mempool.space (fallback blockstream.info) for the outspend of each output. Takes ~15 minutes at a polite rate. """ import csv, json, sys, time, urllib.request rows = list(csv.DictReader(open(sys.argv[1] if len(sys.argv) > 1 else 'first-2016.csv'))) spent = [] for i, r in enumerate(rows): for api in ('https://mempool.space/api/tx/{}/outspend/{}', 'https://blockstream.info/api/tx/{}/outspend/{}'): try: d = json.load(urllib.request.urlopen(urllib.request.Request(api.format(r['txid'], r['vout']), headers={'User-Agent': 'Mozilla/5.0'}), timeout=30)) break except Exception: time.sleep(2) if d.get('spent'): spent.append((int(r['height']), (d.get('status') or {}).get('block_height'))) time.sleep(0.35) unspent = len(rows) - len(spent) - 1 # the genesis output (height 0) can never be spent print(f'outputs checked: {len(rows)}, ever spent: {len(spent)}, never spent (excl. genesis): {unspent} = {unspent * 50} BTC') print('earliest spend block:', min(b for _, b in spent), 'latest spend block:', max(b for _, b in spent))