Just 200 lines of code: blockchain will disrupt every company by 2027
How? Heres how the technology works, and how companies will use it.
It was nearly a decade ago, Satoshi Nakamoto, the creator of Bitcoin, casually disrupted the current trust system in organizations, like banks, by providing a more effective solution with an eight-page long white paper describing how money can be decentralized, and essentially be safer (through Bitcoin).
Before anything, it is important to properly understand what blockchain really is because it is easy to get mixed up with other commonly used terms like transactions, smart contracts or cryptocurrencies.
What is it and how does it work?
In simple terms, a blockchain is basically a database, except it’s an ever-growing database of various different kinds of data and it has quite remarkable properties:
- Once data is stored in the database, it can never be modified or deleted. Every record on a blockchain is permanent for eternity. If anything is changed, a number (hash) associated with the block changes too, and it is obvious that the data has been manipulated.
- No single individual or organization maintains the database; several thousand individuals do, and everyone has a copy of the database themselves.
Still don’t get it, what exactly is it like in real life?
Think of it like this:
Let’s say there are twenty individuals in a group of friends. Everyone in this group is given and starts out with an empty folder and a blank page in front of them. These friends are very close, and so whenever anyone does something important in the network, like transferring money, they announce it to everyone in the network. Everyone makes a note of each announcement on their page until their pages are full.
They keep doing this for everyone and when they’re full, everyone has to seal the contents of their page by solving a mathematical puzzle. Solving a mathematical puzzle verifies that everyone’s page has the same contents and ensures they can never be modified. Whoever seals their page first, gets rewarded with some amount of cryptocurrency.
Once that page is sealed, it is added to the folder. A new page is brought out and the same process continues.
As time passes, these pages (blocks) that contain records of all the important data (transactions) are added to the folder (chain), thus forming the database (blockchain).
Makes sense, how does this all work in code?
A very simple blockchain can actually be implemented in 200 lines of Javascript called NaiveChain. The NaiveChain was created for demonstration and learning purposes. Since it does not have a “mining” algorithm (PoS of PoW) it cannot be used in a public network. But this is a good example of the main functions of a blockchain.
Block structure
The first step is very logical and it is to decide the block structure. At the least, a basic structure must include: index, timestamp, data, hash and previous hash. Notice how the hash of the previous black is included in each of the blocks. This is needed to keep the integrity of the chain.
Generating a block
A block = the hash of the previous block + index, hash, data and timestamp.
Block data is something that is provided by the end-user.
Storing the blocks
A in-memory Javascript array is used to store the blockchain. The first block of the blockchain is always called “genesis-block”, which is hardcoded.
Validating the integrity of blocks
Validating the integrity of your blocks is very important because you must be able to validate the integrity of your blocks at any given time. This is true especially when we receive new blocks from other nodes (other users) and must decide whether to accept them or not.
Choosing the longest chain
There should always be only one explicit set of blocks in the chain at a given time. In case of conflicts (e.g. two nodes both generate block number 72), we choose the chain that has the longest number of blocks.
Controlling the node
The user is able to the user is able to interact with the node in the following ways:
- List all blocks
- Create a new block with a content given by the user
- List or add peers
In code, we can control nodes by setting up a HTTP server:
Node Architecture
The node actually exposes two web servers. One is for the user to control the node (HTTP server) and one is for the peer-to-peer communication between the nodes (Websocket HTTP server).
If by 2027 blockchain will be used by every company, where can they actually use it?
There are many but I have outlined three ways blockchain will affect companies:
- Contracts
- Payments
- Cloud Storage
1) SmartContracts
Blockchain will have a large impact on the way organizations engage with one another as it can help create and ensure more trust between two organizations whoneed to be sure they can trust each other.
In 2017, this trust is provided by a set of pages, or contract, that lists all the terms and conditions of engagement. If a party doesn't adhere to the terms, matters simply go to court, are long and troubling.
Using blockchain technology, many of these contracts can be converted into Smart Contracts which cannot be modified after they are deployed, which ensures neither party in a deal can walk away without doing their part.
2) Payments
One of the biggest promises of blockchain is that it will replace money someday, but as of right now, we can already use blockchains to transfer money across the globe within minutes, instead of days.
One of the benefits of decentralized money is that payments can be transferred directly between peers, without any intermediaries, like banks, slowing down the process.
3) Cloud Storage
According to a recent report by cloud services provider BCSG 64% of small business owners have an average of three cloud solutions in place, which is expected to increase to 72% in the next three years.
Blockchains are playing a huge role in decentralizing cloud storage because they allow strangers to collaborate with each other. Instead of storing files on a single centralized server, you’ll be able to save your files on thousands of devices across the globe which is a lot safer and makes it harder to hack or steal information.
Blockchain is just a tap away…
As easy as it sounds a very simple blockchain can be developed in just 200 lines of code, and I showed you how. Blockchains, as I like to view it in businesses, is a method to make strangers work together, but with trust and security. This technology, however, can have so much potential and use cases in various different companies. These are just a few things to expect but the possibilities are truly endless. And these possibilities are very close to becoming realities.
If you enjoyed reading this article, please press the👏 button.
Follow me to stay updated on my future articles. Also, feel free to share this article with others!