Blockchain is a distributed & decentralized ledger that stores data and is publicly shared across all the node of its network. Blockchain is almost always used instead of the terms Bitcoin and cryptocurrency. And there are many other places this technology can be used. We are beginning to barely scratch the surface of it.With all the popularity around, we know that the Blockchain Technology is going to be huge. But what makes it unique?
- Decentralized System
- Distributed Ledger
- Secure Ecosystem
- Mining
- Chronological and Time stamped
- Consensus Based
Let’s look into these in more detail.
1. Decentralized System
Blockchain is a Decentralized Technology, by design.
When something is controlled by a central authority, where the power to make decision lies in the hands of the apex of the management, such system is called a Centralized System. Banks, for example, are a centralized system, where it’s the responsibility of the Governor to make decisions.
On the contrary, when the power is vested in the hands of the people or the users, such system is said to be a Decentralized System. The peer to peer network, Torrent, for example is a decentralised system, where the user has complete control.
2. Distributed Ledger
Blockchains use distributed Ledger Technology (DLT) to store and access the data around.
When something is stored on a Distributed Ledger, multiple copies of it are made across the network at the same time. Unlike traditional databases, distributed ledger do not have a central database or administration functionality.When applied in a decentralized system like Blockchain, each user has a copy of the ledger and participates in the transaction verification. This gives Blockchain the property of Immutability and ensures security. Since, the data is distributed, there is no centralized version of the data for the hackers to corrupt. The data and the records are public and easily verifiable. This also eliminates single point of Failure.
3. Secure Ecosystem
BlockTech uses the concepts like Proof of Work and Hash encryption to ensure security and immutability. Proof of work involves several people around the world using computational algorithm to try and find the appropriate hash value that satisfies a predefined condition regarding the hash value.
4. Mining
Torrent is a peer-to-peer decentralised network used to share files. BlockTech uses similar technology. What differentiates the users is that, in Torrent, the system relies on the honor code of the users to seed the files. Whereas, in blockchain, the users who are involved in the transaction have economic incentives. These users are called “Miners.” The Miners spend their computing resources to solve the cryptographic hashes and ensure immutability and reliability of the transaction. Every successful solution (decryption) ensures some economic benefit.
5. Chronological and Time stamped
Blockchains, ideally, are just very sophisticated linked lists where each block is a repository that stores information pertaining to a transaction and also links to the previous block in the same transaction. These blocks are arranged in an order and are time-stamped during creation to ensure a fair record.
6. Consensus Based
Consensus Based is an approach to decision making. It is a creative and dynamic way of reaching agreement between all members of a group. A transaction on Blockchain can be executed only if all the parties on the network unanimously approve it. It is however, subjected to alterations to suit various circumstances.
Why use blockchain?
What happens if you and your friend independently and separately conduct the same petition campaign? Let’s say it’s for the “save the planet” cause.
Let’s say you conduct it in an identical sequence across the same continent, but come up with different sets of signatures on the petition. Which version of the signed petition is the “source of truth”?
You would need to trace back your separate trails, one signature at a time, to locate the last discrepancy. And then you’d have to work further back to identify the first result that diverged between your signature sheets. Prior to that root divergence, all other signatures on the two lists should match up.
You then know that prior to that divergence. Both lists are in accord, so those signatures represent the minimum number of people who signed to support saving the planet.
While that may work well for planet and continental surveys, it doesn’t work so well in the digital world. or voting, banking, financial transactions, transferring land title, discharging contractual obligations etc. You need independent and “trusted third parties” to verify a chain of events, and solemnly reassure you that the “chain of custody” was unbroken.
A “chain of custody” can sometimes also be called the “provenance” – they both mean the same thing: the sequence of historical events concerning the data in question.
That’s why you have governments having the final say on your identity, and votes need to be physically counted and recounted by hundreds of volunteers, and clerks in dingy offices maintain ledgers and certificates to confirm whether or not you own your farm/white picket-fenced bungalow.
That is why you need financial intermediaries to ensure that when you buy your CR7 Jersey, using a credit card, the money (value) is “removed” from your account and “added into” to the seller’s account.
This is technically called the “double spending problem” – how do you ensure that you’re not spending the same money twice? Without someone to do this, you could spend money and at the same time continue to hold on to that money.
So it’s a big problem really – modern life requires that we rely on, trust in and pay for “trusted” third party intermediaries to ensure that value (money) does actually digitally “change hands”. That is why Visa and MasterCard exist, and why PayPal and others link with your bank accounts.
How Blockchain works?
It is essential to remember that the blockchain is a technology – mathematically complex software code to be specific. And Bitcoin (or Ethereum or any of the other cryptos on offer) are just applications of that technology.
So the key principles are:
- Blockchains are ‘mined” (produced through the expenditure of effort, like in gold mining) by powerful and resource-hungry computers – called nodes, that are on the same network.
- Chains of digitally encrypted and timestamped records of transactions are lumped into “blocks”, which are maintained on a “ledger” by each node. As transactions are added to a block, and blocks are linked together linearly and chronologically as “chains”. Then the entire record/ledger gets synchronised across the network of nodes such that all the block “chains” on the nodes should tell an identical story of the history of any given transaction. Thus we get “block + chain = blockchain”. It’s a long, complicated linked list.
- Each block in a chain has its own id – a cryptographic hash that is unique and specific to each block. That hash is also stored in the next block in the chain, causing a link. A block can store thousands of transactions and the tiniest change in that block’s data would result in a new hash. So if a hash changes but the next block has a different hash, then we know some data in the previous block was tampered with.
- As hundreds become thousands of nodes (and more are added all the time), each node has to “agree” on the history of the blocks/ledger – this is called “critical consensus”. One of the ways in which consensus is achieved is through the cryptographic hash we talked about earlier.
- Where there are discrepancies in the ledger (for example the hash of a block doesn’t match with the next block’s reference to the previous block’s hash), the ledger with the longest chain of valid transactions embedded will be the “correct” one – the source of truth. Any nodes working on other (shorter versions) of the chain switch to the longer one. This maintains the critical consensus (this bit is hugely oversimplified, but sufficient for now).
- Any naughty interception or change to one ledger (again, for example, where a block’s hash doesn’t tally) would immediately create a discrepancy with all the other versions. It would also have a shorter block “history” to corroborate it, which makes that tampered version a suspicious character in the blockchain network where length matters .
- Replicating that discrepancy across all the versions of the ledger – the entire blockchain network – is such a huge task that it is computationally impractical, and would only happen if the bad guys suddenly had control over the majority of the nodes mining blockchain and changed them all rather rapidly. This sort of coordinated attack on the majority of the nodes on the network is often called the 51% attack.
Let’s Code a Simple blockchain:
Create a file name index.js and paste the code below:
const simpleHash = (data) => { //simple hash function(not a cryptographic algorithm);return data + '*'; } class Block { constructor (data , hash , lastHash){ //data:what the block is storingthis.data = data;//hash:generates unique string everytime with some cryptographic algorithmthis.hash = hash;//lastHash:creates a link between new block and last blockthis.lastHash = lastHash; } } class Blockchain { constructor() { //initial block for the chainconst genesis = new Block('gen-data' , 'gen-hash' , 'gen-lastHash');this.chain = [genesis]; } //incoming blocks links to initial block addBlock(data) { const lastHash = this.chain[this.chain.length-1].hash; const hash = simpleHash(data + lastHash); const block = new Block(data ,hash , lastHash); this.chain.push(block); } } const theBlockChain = new Blockchain(); theBlockChain.addBlock('one'); theBlockChain.addBlock('two'); theBlockChain.addBlock('three'); theBlockChain.addBlock('four'); theBlockChain.addBlock('five'); theBlockChain.addBlock('six'); theBlockChain.addBlock('seven'); console.log(theBlockChain);
If you execute this file you’ll get the following output:
Blockchain { chain: [ Block { data: 'gen-data', hash: 'gen-hash', lastHash: 'gen-lastHash' }, Block { data: 'one', hash: 'onegen-hash*', lastHash: 'gen-hash' }, Block { data: 'two', hash: 'twoonegen-hash**', lastHash: 'onegen-hash*' }, Block { data: 'three', hash: 'threetwoonegen-hash***', lastHash: 'twoonegen-hash**' }, Block { data: 'four', hash: 'fourthreetwoonegen-hash****', lastHash: 'threetwoonegen-hash***' }, Block { data: 'five', hash: 'fivefourthreetwoonegen-hash*****', lastHash: 'fourthreetwoonegen-hash****' }, Block { data: 'six', hash: 'sixfivefourthreetwoonegen-hash******', lastHash: 'fivefourthreetwoonegen-hash*****' }, Block { data: 'seven', hash: 'sevensixfivefourthreetwoonegen-hash*******', lastHash: 'sixfivefourthreetwoonegen-hash******' } ] }
Happy Coding …