Introduction: From Buzzword to Building Blocks
The word blockchain gets thrown around everywhere — usually surrounded by hype, buzzwords, and way too much mystery. I used to think it was some alien-level technology. But I found the best way to really understand it wasn’t by reading definitions — it was by building one myself.
So I decided to make a simple blockchain from scratch in Go. The process completely changed how I saw it. Under all the complexity, blockchain is built on a few clean, almost obvious ideas. Here are the five biggest “aha!” moments I had — the ones that turned the concept from something abstract into something I could actually reason about and code.
1. A Blockchain Is Just a Linked List with Rules
The first big surprise: a blockchain’s core structure isn’t exotic at all. It’s basically a glorified linked list with some cryptographic glue holding it together.
The basic components:
- Transaction — holds from_address, to_address, and value
- Block — contains a list of transactions, a timestamp, and a field called PreviousHash
- Blockchain — just a slice (blocks []*Block) that stores all the blocks
Each block saves the hash of the previous one. That single rule — every block pointing back via hash — is what makes it tamper-evident. The magic isn’t in some fancy data structure, it’s in applying simple cryptography to something familiar.
2. “Mining” Is Literally Just Guessing Until You Get Lucky
I always imagined mining as some super-complicated math problem. Turns out, it’s just brute-force guessing. Proof of Work is basically a loop that keeps changing a number (called nonce) until the resulting hash starts with enough zeros.
In my code, it goes like this:
Set nonce = 0
Combine transactions, previous hash, and nonce into a block
Hash the whole thing
Check if the hash starts with the required number of leading zeros (mining_difficulty)
If not, increment nonce and repeat
That’s it. Pure trial and error. When I increased difficulty from 4 to 5, and then to 6, the mining time shot up — instantly showing how difficulty scales with computation. Mining isn’t complex, it’s just hard on purpose.
3. New Coins Come Out of Thin Air (a “Digital Faucet”)
One thing that confused me early: if every transaction just moves coins around, where do new coins come from? The answer is surprisingly simple — they’re created from nothing as a mining reward.
When a miner finds a valid block, the program creates a reward transaction. Its from_address is something like "Evo chain faucet". That faucet isn’t a real wallet, so it doesn’t have a private key. Because it can’t sign anything, the transaction has to be added manually to the block — it’s not verified like normal ones.
That’s literally how new currency enters the system: the code itself mints it as a reward for doing the computational work. In my setup, it was 1200 EVO per block. Kind of wild to see “money” just appear because a loop found a hash with enough zeros.
4. The Whole Chain Gets Saved Every Time Something Changes
Persistence was another thing that surprised me. Without a database, the blockchain only lives in memory and disappears when the app stops.
I used LevelDB as a simple key-value store. The persistence logic was super direct:
Serialize the whole blockchain struct as a JSON string
Save it in the DB under one key, "blockchain_key"
And every time anything changes — new transaction, new block — the entire chain gets serialized and written again. It’s definitely not efficient for a big system, but it’s dead simple and reliable for a prototype. No state gets lost.
5. Wallet Balances Aren’t Stored — They’re Rebuilt from History
This one blew my mind: there’s no “balance” field stored anywhere. To get your wallet balance, the program recalculates it every time by replaying every transaction in history.
My first version only added incoming funds, which gave wrong results. The correct approach:
Start from zero
Loop through every block
Loop through every transaction inside it
If to_address == target, add value
If from_address == target, subtract value
At the end, the sum is your balance. Nothing is stored — the balance emerges from the chain’s full transaction history. In this world, history is the state.
Conclusion
Building a blockchain by hand stripped away the hype. What’s left is something surprisingly elegant:
A linked list with cryptographic links
A brute-force guessing loop for consensus
A code-driven faucet that mints new coins
A state that’s just the sum of its entire past
Once you see it that way, blockchain stops feeling like black magic — and starts looking like one of the simplest, smartest systems you could ever build.
Top comments (0)