Hackernoon logoWhy I Decided to Build Bitcoin from Scratch by@tomgoldenberg

Why I Decided to Build Bitcoin from Scratch

Author profile picture

@tomgoldenbergTom Goldenberg

I first heard about Bitcoin at my first programming job at a machine learning startup. A co-worker who was of the tinfoil hat type (the kind that insists that you use Protonmail) told me about it. I was skeptical and paid no mind. Foolish on my part.

Years later, I became CTO and co-founder of an online investing platform. Several months in, my partner and I considered adding support for cryptocurrencies like Bitcoin. I resolved to get acquainted with these assets in depth before offering them to clients.

I started with Satoshi Nakamoto’s white paper. I was taken back by what I found — a clear and precise explanation that I could quickly grasp. With newly found confidence in Bitcoin, I pressured our team to add support for crypto. And we became the first online advisor in the US to offer both stocks and cryptocurrencies to investors.

Digging Deeper

After we launched support for crypto, we started getting significant traction. But one month later, Robinhood announced that they were going to support crypto trading. They garnered over a million signups for the feature.

Investors raised questions about our ability to compete with a sizable, well-funded startup like Robinhood, and we eventually decided to wind down operations and close the company. My partner joined a blockchain startup and I signed with a large consulting firm.

I knew that I wanted to focus on blockchain technology going forwards. So once we closed operations, I dove into the Bitcoin source code. My conviction was that the best way to understand the future of blockchain is to start with Bitcoin. So I set out to build it from scratch. Here’s my thinking:

my version of the Galaxy meme

Method to the Madness

How does a person code Bitcoin from scratch? First I needed to learn C++, a programming language I had never used. There was a dusty copy of “C++ for Dummies” on my book shelf that I had never read. It was a gift from my father-in-law, which is strange since I never expressed a desire to learn C++.

my source code copies

After learning the basics of C++, I printed out the entire source code of the earliest version of Bitcoin. I stapled together sections and organized the files according to their importance. My main focus was on the large files main.h, main.cpp, net.h, and net.cpp.

The next few weeks I brought these files with me everywhere. I studied them on the train, subway, and on flights. I jotted down questions that I had about the code — Why is this class referenced here? Why is this value chosen? What exactly is mapOrphanBlocks?

At the same time, I practiced by writing each line of code myself. This forced me to focus on each expression and record my understanding of it. I also searched forums like Bitcointalk.org and Stack Overflow for answers to my questions. When I felt that I understood a piece of the code, I set out to interpret it in JavaScript (my “native” language).

Learning by Doing

Before learning to code, my claim to fame was being adept at learning difficult languages. I taught Sanskrit at an Indian university after having studied it for less than two years.

One thing I learned from gaining fluency in Sanskrit, Spanish, and Malayalam is this — learning by doing is very effective. It is variously called “immersive learning” or “project-based learning.” Intrinsic motivation will always outperform meaningless exercises, which is why I chose to put a real goal in front of me while learning about blockchain and C++.

In the process of learning a language, there is a point where it feels like you are stepping out of darkness and into light. It is one of the most exhilarating experiences I know of. Learning Bitcoin by building it gave me the same sensation.

Initial Implementation

Bitcoin’s architecture is comprised of several parts. You need a way for nodes to connect and communicate with each other. You also need rules for forming a consensus, validating blocks, and syncing all of the nodes.

My initial implementation took some shortcuts but I was able to get a blockchain up and running soon. I can only imagine how Satoshi Nakamoto felt seeing his initial idea take form and grow into a huge network. I felt like I had created something alive, organic.

My blockchain lacked some key features, such as a self-adjusting difficulty, merkle hashes, and advanced scripting. But it met most of the criteria of the white paper — peer-to-peer networking, mining, and block creation. I decided to open source my creation and have started writing about the steps I took.

Conclusion

Building Bitcoin from scratch has opened my eyes to the possibilities of blockchain, as well as its limitations. I would recommend to anyone interested in a new technology to build something meaningful with it first. It will de-mystify the concepts and give greater clarity on what it can be used for.

For me, the promise of Bitcoin is the promise of security. It is technically impossible for a single actor to “hack” the private keys of all participants. Meanwhile, centralized data stores get hacked all of the time — Equifax, Target, etc.

Regardless of where Bitcoin ends up, it and its anonymous creator have certainly made an impact. And it is my belief that much of that impact has yet to be felt.

If you liked this article, please clap 👏👏👏

Tags

The Noonification banner

Subscribe to get your daily round-up of top tech stories!