3 Things I learned from building a Blockchain

“Geometric blue abstract cubic art design mural over number 33 tile sign in Brighton” by Charlotte Coneybeer on Unsplash

Blockchains are one of the most exciting technologies to have come out in a while and they have the potential to revolutionize some industries. The best way to learn a technology is to use in practice, so I built a basic blockchain by following an excellent tutorial here. After building a blockchain here is what I learned.

1. Blockchains are Simple…sort of

Photo by Samuel Zeller on Unsplash

I don’t like to say anything is simple but I believe even a non-experienced person can understand the fundamental ideas of blockchains.

Lets first define blockchain, you could search for many definitions for blockchain but you’re reading my article so I’ll save you the trouble and give you my definition.

“A blockchain is a public chronological list of transactions known as ‘blocks’, where each block contains a secure hash and a reference to the hash of the previous block.”

The first point to take away is that the list of transactions are chronological and publically accessible by anyone. The order helps prevent fraud and being publically accessible provides transparency, which are two major strengths of blockchains.

The second point is every block contains a unique sequence of characters known as a hash and contains the hash of the previous block. Different functions can be used to create hashes but generally they will take an input that is unique to the block and output a unique value for the block.

If you understood the last four sentences, then congrats! Those are the basic ideas of how a blockchain works. The “sort of” part in the title come from the fact that all blockchains are more complicated but they will all have these basics in common.

2. Proof of Work Regulates Blockchain

“Letter buttons on an old, dirty jukebox.” by Diomari Madulara on Unsplash

In the blockchain definition I gave earlier I mentioned that every block in a blockchain represents a transaction. Every time a transaction occurs there are computers that verify the transaction and add it to the chain. Each computer has a copy of the blockchain and if one of the computers successfully adds a block to the chain then that computer’s copy of the blockchain becomes the master copy. The computers that add to the blockchain are more popularly known as “miners”.

The problem is that an evil miner can come along and attempt to make their version of the blockchain the master copy. This can lead to problems such as altered transaction, fake transactions, and dropped transaction. The solution is a Proof of Work(POW) algorithm. POW is a mathematical puzzle that needs to be solved by a miner before they can add their block to the blockchain. The key properties of POW is that it needs to be difficult to compute but easy to verify. There is also the nonce (short for “number only used once”) which is just a random number, that will be useful soon. Let’s go through a simple example.

In our example the POW puzzle is to find a number that ends in “4”, the algorithm takes in the hash of the block and the nonce number and produces a guess. It is likely that the guess won’t solve the POW puzzle on the first try. Since we can’t change the data stored in the block, we will change the nonce number and then try again. If the guess still isn’t correct we keep changing the nonce until we have a number that solves the POW puzzle and then we can add the block to the chain. Implementing a POW for a blockchain is crucial so that the creation of blocks is delayed and it helps regulate and prevent attacks on the blockchain.

There is also an alternative method called Proof of Stake but I’m planning to write about that for another article so make sure you follow to stay up to date!

3. Blockchains Potential is Smart Contracts

“fountain pen on black lined paper” by Aaron Burden on Unsplash

The last point I want to bring up are Smart Contracts which is where I believe blockchain has the greatest potential. I’ve talked about how blocks store data but with smart contracts you are storing actual code in each block.

The smart contract code works like a normal contract except for a few key differences.

The first difference is that it is free of any third party interference. Since the code is stored on the blockchain it does not have to be maintained by a single party and it can exist on its own. The contract has listeners that can listen for different values and execute functions on its own. An example would be if you bet money on your sports team winning, the contract could listen for sports score and then automatically transfer the money to the winner of the bet without the need of a third party to execute the contract.

The second difference is that the contract is immutable, which the means the conditions in the contract can’t change. There is no need to worry about a contract updating and then blindly accepting the changes. Since the blockchain is also secure you don’t have to worry about hackers trying to change the contract conditions. An example of this is if there was a crowdfunding site and you contributed money to reach a certain goal, you don’t have to worry the receiver will try to secretly change the goal to earn money.

Even though I gave small examples that show the benefits of smart contracts there are definitely more situations where smart contracts can come in handy. Feel free to comment about ideas where you think smart contracts would be useful!

Conclusion

So those were the three main takeaways I got from building a blockchain and I’m planning to explore more in the blockchain world and keep writing about it. If you have any questions feel free to ask in the comments!

The blockchain industry is only beginning to take off and it has a very interesting future ahead.

--

--

Software engineer interested in cutting edge technologies and loves to write about them. https://nadimuddin.com/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nadim Uddin

Software engineer interested in cutting edge technologies and loves to write about them. https://nadimuddin.com/