Demystifying Blockchain!
Ethereum, mining, blockchain, smart contracts, ethers, bitcoins(Suddenly your inner voice is like ‘hey! I know bitcoins!’) — I’m sure you would have heard all these jargons many times online on most of the related articles, blog posts, news etc. I don’t blame you if you are super confused when you hear about blockchain technology and how they work, I agree, they are seductively alluring. I started looking into ethereum just a couple of months back for a quick project and I must say, I am in love with it.
This post is going to be huge and will be split into multiple parts, the first part will give the readers an idea on the whole ecosystem, the second part will be a bit technical.
So, the most obvious question that pops up. What is blockchain? Lets us look into some quick history.
When the first genesis block was mined in the bitcoin network..
Nearly a decade ago, A mysterious person with a pseudonym invented this phenomenal technology called bitcoins — A decentralized cryptocurrency.
The word decentralized here simply means that there is no central authority who is responsible for your transaction, instead it is done in a peer-to-peer manner, something similar to how bittorrent or skype works.
The high level concept of how a bitcoin works is pretty straight forward, you are given a public-private key pair, you own a digital wallet , you transfer bitcoins to people by using their address. (if you are computer person, does this ring a bell? yes, SSH!)
Every wallet is connected to the bitcoin network, any transaction that you do will be mined in order for the transaction to take place and the transaction is pushed into the distributed ledger.
Still scratching your head?
Perpetual optimism, please! — read on..
Let us look into an example. First the transaction part — Both Marr and Morrissey got a wallet that is connected to the network, each with some cryptocurrency(ex: bitcoin). Morrissey wants to transfer about 10BTC to Marr — Morrissey would just open up his wallet, enter Marr’s address, enter 10BTC and press the Send button(Provided he’s got 10BTC, Duuh!) Thats it! You can even see the transaction happening live here
Now, the mining part, the transaction that you just did requires some sort of compute resource to be executed. Well, in a typical centralized system you have your bank or some other financial body doing it for you, but in the blockchain the miners are basically folks running their CPUs and GPUs, overclocking it to push your transaction into a block and helping you complete your transaction, in return they get a small reward — they get to make a transaction of 25BTC to their own account of out of thin air.
Now we all know Morrissey just sent money to Marr in no time and the transaction is present in the blockchain.
[Security and more details about how the miners push blocks are beyond the scope of this article — I will try to write another post in the future on this]
It was in january, 2009 the genesis block which is the first block of the bitcoin network was mined. Hope you now know what blocks are, they hold all transactions. All the blocks in the blockchain contain the previous blocks reference except for one block, that is the genesis block — The block 0(zero) which is hardcoded into the network.
From a technology standpoint, blocks are the fundamental unit of data in our distributed ledger. Consider blockchain to be a replicated database which is synced with peer-to-peer network between all the nodes that are connected to it. Blocks are analogous to typical tables that hold all your transactions(state). Miners are your compute which help you push Tx into these blocks.
[Any expert would find the above statement oversimplified since blockchain is not suitable for all the usecases of a typical db, but this is just to set a premise for the beginners to go forward]
Significance of a bitcoin network:
- Open network
- Instant transaction
- Extremely fast and safe
- Very cheap as well.
Now that you know how awesome bitcoins are, but their awesomeness is solely due to the underlying technology that makes it happen — The blockchain.
The famous bitcoin is one of the poor applications of blockchain (If you’re a purist, you must be cursing me now), in fact it doesn’t leverage the most out of what blockchain is capable of. That is where I believe, ethereum comes into the picture.
What is Ethereum?
Before I explain what ethereum is all about, let us get into a admittedly simplified scenario. You are going on a holiday trip to the cryptoland and you check-in to a cryptohotel, you have a digital identity on a network with which all the services/products are connected to the cryptonetwork.
Now when you check-in, an autonomous entity at the reception which is programmed on what it is supposed to do will read your address, check if it has got enough money(state actually — more on that later) and allot you a room. It will also update the other autonomous entities like room service system, periodic cleaning system etc.
You decide to go for a little sight seeing, you have your own identity and all the systems are connected to the cryptonetwork and interaction with all the systems becomes almost simple and instantaneous. From renting a car or bicycle to paying to a food vending machine, everything becomes hassle free and absolutely simple.
Isn’t this possible with any well connected city with a bunch of centralized servers and softwares running on the cloud?
Yes, I admit the above scenario was just to give you a simple idea of how the network works, plus the above scenario merely just touches the autonomous nature of systems involved in the blockchain where multiple autonomous entities are connected which are programmed. But the above scenario solves a major pain point — Identity management. With blockchain in place, people’s identity problem does not exist and that makes it efficient during transactions and other interactions.
But imagine the amount of processes and paperwork involved in an average business proceedings, insurance claims, buying of an house — when you are able to digitize all contractual instruments, not only it cuts down your paperwork by 90% it also gives you a permanent digital proof. It would help in reducing cost and ease the litigation system.
How does this relate to ethereum?
Ethereum is a decentralized platform to run your smart contracts to do exactly what it is programmed to do without third-party interference, it is safe and secure. Using ethereum you could build a decentralized application(Dapp in short) which will interact with the smart contracts that you write and do what it is intended to do. Predefined rules are programmatically set in the smart contracts.
How do I build the dapp and make it work with ethereum?
Let me try and connect the dots here, A typical application is going to have a front-end UI(client side or browser side) and a server-side which is connected to a db layer. Any request that you send from the UI is pushed to the server side and hence the action is performed. All the data, actions, states are performed/stored within the servers of the app alone, in other words — a centralized system.
But, in a typical Dapp, there is no such thing as a centralized backend with a db layer. You build your front-end UI, then you write smart contracts(programs) and you deploy these contracts into the ethereum network, the miners will help you do that and then you make your Dapp talk to the smart contracts that you wrote to do further actions.
Now, all the Internet of Things devices from the cryptoland — reception bot, hotel cleaning service, bicycle, food vending machine are all autonomous machines connected to the blockchain with their own smart contracts deployed . All you need is some ethers on your wallet and you are good to go. What bitcoins are to the bitcoin-blockchain network, ethers are to the ethereum-blockchain network. They are just another cryptocurrency that are used in the ethereum network. Ethers are, as they call it — cryptofuel.
Cryptocurrencies and crowdfunding:
Let us say, you decide to build your own cryptoland. It is your dream city full of entertainment and a lot of fun things to do. You personalize it to the fullest, now you may think of your own currency. Since everything is connected over to the blockchain, a cryptocurrency, indeed!
Yes, creating your own cryptocurrency is very simple on ethereum. You need to define a contract with n number of tokens, the amount you want in circulation and the contract will hold the tokens.
Tokens? Tokens can represent a value that you provide. You can make a contract hold 100 tokens and back it with dollars or even the service you offer.
Ex: Digix’s gold tokens are backed up by real gold.
Once the contract is deployed onto the blockchain, people can pay money for your tokens in exchanges and get them. They could use those for all the blockchain services in your own cryptoland. Similarly it is also possible to build a crowdfunding platform with no central authority. The possibilities are endless.
Few key words:
Dapp — Decentralized application with just the front-end connected to the ethereum network(or any other blockchain network) A wallet is a Dapp.
Smart contracts — Smart programs/scripts that are deployed in the blockchain network, acts as the backend for your Dapp.
Miners — They are your distributed compute resources to run your smart contracts for which they get rewarded.
Ethers — Similar to bitcoins, they are a cryptocurrency in the ethereum network. You need ethers to deploy a smart contract and do further actions on the ethereum mainnet.
What is a consensus system?
The genesis block is the only hard coded initial block and each transaction is pushed into the block by the miners in a sequential manner. Note, the order of the transactions placed in the block matters. Essentially each transaction provides a valid state transition from the canonical state to a new state.
A consensus system, in a way can be considered to be a validating system, which validates the transaction and helps the miners push the transaction into the block. An attacker can make a Tx and spend money, then later reverse the transaction by broadcasting his own blockchain which would not have the transaction, since there are no centralized authority to validate the blockchain and it is done in a peer-to-peer fashion, a complex mechanism is required — The Proof of Work consensus mechanism.
Miners will have to solve a computationally complex problem to validate the block and in return they get bitcoins.
There are two consensus mechanisms:
- Proof of Work
- Proof of Stake
The famous bitcoin network uses the proof of work consensus mechanism. The Proof of Work consensus algorithm is very effective, it solves two major problems,
First, it helps the node belonging to the network to collectively agree on the state of the blockchain ledger.
Second, It prevents sybil attacks but at the same time allowing anyone to be a part of the chain, removing a central deciding authority.
What is the difference between PoW and PoS?
A Proof of Work consensus algorithm works like this -
A miner with p fraction of computational power can create a block with p probability. In other words, the chances of creating a block by a miner is directly proportional to the compute power the miners got.
This may prevent an attacker to alter the blockchain, it is possible only if he exceeds the computational power of all the nodes involved, which would be expensive.
The Proof of Stake on the other hand, does not depend on the computations resources, but on the users’s stake in the system. A p fraction of ownership stake can create a block with p probability.
This is a lot cheaper since there is no constant race in increasing the resources to keep the network alive.
End
I hope I covered pretty well on the basics of what and how blockchain, bitcoin and ethereum works.
The next post involves setting up a private ethereum network, building a simple Dapp and deploying a contract to the blockchain network.
Thanks!