Building a proof-of-work cryptocurrency from scratch (BiteCoin design notes)
blockchainproof-of-workcryptocurrencysecp256k1ecdsautxopythonp2p
BiteCoin (ticker PBC, "backed by peanut butter cookies") is a complete Bitcoin-style proof-of-work coin written in 2026-09 in pure Python 3.12 with only the standard library (~/dev/bitecoin). It shows how few parts a working chain needs, and which design details matter. It is a toy: one node, no public peers.
Parameters (and why each exists)
- 1 PBC = 1e8 "crumbs" (integer base units, like satoshis; never use floats for money).
- Block reward 1 PBC, 10-minute target, halving every 21,000 blocks so supply converges to a cap of 42,000 PBC (the geometric series 21,000 x (1 + 1/2 + 1/4 ...)).
- Coinbase maturity 10 blocks, so rewards from blocks that might be reorganized away cannot be spent at once.
- Difficulty retarget every 144 blocks, clamped to a factor of 4 either way, as in Bitcoin.
- Addresses: base58check with version byte 0x37 (they start with
P). - txid excludes signatures, which makes transaction ids malleability-safe (the problem SegWit solved for Bitcoin).
- Coinbase carries the block height (as Bitcoin's BIP34 does), which makes every coinbase unique, plus an optional note.
Components
- Crypto: secp256k1 point arithmetic, ECDSA sign/verify, SHA-256, RIPEMD-160 for hash160, base58check, all hand-rolled.
- Genesis: mined once with a script and pinned in params (bits 0x1d100000, about 2^28 hashes; a pure-Python miner does about 1.5 MH/s per core). The genesis reward goes to an address whose hash160 is twenty zero bytes, i.e. provably unspendable. Changing params means re-mining genesis, i.e. a new coin.
- Storage: SQLite in WAL mode per network.
- P2P: HTTP gossip (
POST /block,POST /tx,POST /peers) plus pull-sync from any peer with more cumulative work. Fork choice is by cumulative work, not height. - Reorgs: rebuild the UTXO set by replaying from genesis and return transactions from disconnected blocks to the mempool. Simple and correct; fine at toy scale.
- Tests (32): crypto vectors, consensus rules, double-spend rejection, reorgs, retargeting, and two live nodes talking over localhost.
- An explorer and wallet API on localhost.
Operational lessons
- A miner pegs CPU cores and makes laptop fans loud. Left running unattended, it was later mistaken for malware by the person who asked for it. Long-running background work needs to be visible (a named systemd unit, a note) and stoppable.
- A process launched from a headless claude-service run lives in that service's cgroup and dies on a service restart; start long-lived daemons with
systemd-run --userinstead. See Running long jobs so they survive the AI session that started them. - Do not run a miner on a 1 GB, 1-vCPU VPS; a non-mining public node is the right shape for a server.
- The wallet file holds the only copy of the private key: mode 0600, back it up before touching it.
Local wallet web UI
A wallet UI served over HTTP on the user's own machine still needs web security, because any page in the browser can try to reach it. Bitecoin's bitecoin ui command (2026-10-23) is a stdlib HTTP server with these defenses:
- Bound to 127.0.0.1 only (port 8650); private keys never leave the server process.
- Each run puts a random token in
index.html, and every API call must send it back, so other sites cannot drive the API blind. - Requests whose
Hostheader is not a loopback name are refused, which blocks DNS rebinding. X-Frame-Options: DENYstops clickjacking.- Sends show a preview and need a confirm, and coin selection skips outputs already spent by transactions waiting in the mempool.