Tadcoin: the story of how I coded a blockchain.

Eren Suner
4 min readMar 1, 2020

Heyyo! Roughly 3 months ago I decided to code my own blockchain. Here are my takeaways and the story of it all.

Takeaway 1: I procrastinated for the 2 out of 3 months. 2 out of 3. Solely because I didn’t know what I was doing and didn’t have the courage to admit it. My first take away is to not let my ego blur my way.

Takeaway 2: Break it down. Even though I knew the principle of dividing and conquering I thought I didn’t really need it since I was such a seasoned developer. Towards the end of the project, I properly broke it down and left some unnecessary parts out.

Takeaway 3 — the 10 minute agreement: This is my ultimate method to get rid of procrastination in a calm and not-over-emotional manner. I just tell myself: “I’ll do x for 10 minutes, if I still wanna do it I’ll keep going, otherwise I’ll do something else.” Works every. single. time.

The Story

I live near a shoppers drug mart (a supermarket) and I genuinely hate seeing the workers wasting their lives doing something a robot could do. That got me thinking, why the hell are these people doing this? For money, which is a representation of value. What else is a representation of value? Blockchain. I needed to learn how value is packaged and managed to save those people from the need of having more value (=money) which entails working like a slave in a boooooorrring job.

That was a romantic entry wasn’t it? After you start coding, the romance dissipates, especially after realizing it’s not a smart strategy to implement bitcoin from the paper alone.

So I found some online courses, like the cryptocurrency design course at MIT Open Course Ware, or the Stanford Cryptography course on Coursera and tried those and learned a ton. Then I started implementing it.

I researched what libraries to use and found ecdsa, a public-key-cryptography library for python. I’ve also found a peer-to-peer networking library, although I didn’t use it since networking was not what I was trying to learn.

Technical Analysis

If you don’t know anything about how a blockchain works, check out my article for beginners.

The structure of the project consists mainly of 4 files: blockchain.py, block.py, transaction.py and crypto.py

Crypto.py -> Read the source code before jumping to the analysis.

Here I have all the functions for hashing and public-key cryptography. I’ve also added a feature to open and save key pairs. Most of these features are provided by the ecdsa library.

One interesting function I have here is the verify public key function, which checks if a given transaction is from its intended sender or not.

Transaction.py -> Read it, or it won’t make sense.

Here’s my transaction implementation. Although it’s quite a bit different from bitcoin’s implementation it still carries the same functionality. One interesting class I have is the money_created class which is for generating value in the blockchain by awarding the miners (public keys = accounts, which do the work in the proof of work).

Block.py

As you see I have a block class. There are 2 interesting methods here, the mine method which does the “work” in the proof of work consensus algorithm by changing the nonce until the hash of the block starts with “0000”. In a real-world system, the number of 0’s would be correlated with the amount of time it takes to generate a block, to keep the block time stable.

The compute_merkle_root method computes the Merkle root by going through all the transactions, taking their hashes, concatenate them, then take their hashes until there’s only one hash left, that is the Merkle root.

Blockchain.py

The add_block function adds blocks to the chain, and the search pubkey function is used for determining the balance of a given public key.

About Me

I’m a 16-year-old blockchain enthusiast working on cool projects. Follow me on Twitter @ErenSuner2.

Check out my website.

--

--