In this blog, we will be learning Ethereum, Types of Nodes, Smart Contract, DApps, Ethereum Virtual Machine, DAOs. Tighten your seat belts and enjoy the ride!
Ethereum is also a P2P distributed ledger just like Bitcoin but it allowed us to host smart contracts and Decentralised apps on top of the chain.
Ethereum was invented by Vitalik Buterin in 2015, the aim was to broaden the use case of blockchain by enabling applications to be hosted upon the chain as smart contracts. Ethereum transitioned from Proof-Of-Work based protocol to Proof-Of-Stake which is proven to be faster than previous by a huge margin. In Proof-Of-Stake miners stake minimum 32 ETH and then validate the transactions. If some miner maliciously tries to mine a block with the wrong transactions, the network will reject the block and the miner will be fined and the amount will be deducted from his/her stake.
But unlike Bitcoin where every node was a miner, here it can be classified into 3 categories — Full Node, Light Node & Archieve Node. You can be any type of node based on your resources and purpose.
Ethereum accounts hold all your ethereum UTXOs and allow you to transfer or receive ethereum and also interact with smart contracts. Types of Ethereum accounts — Externally Owned Accounts & Contract Account. To put it simply, the externally owned accounts are created when you create your wallet. It has Public and Private Keys but there is no concept of GAS Fees. Contract account is ethereum account which will be managed by smart contract. It does not have any Public or Private Keys. Both accounts hold ETH balance.
What is Smart Contract ? It is a program which runs on blockchain. As every node has a copy of a deployed Smart contract running on their machine, there is no way of defaulting out. So what if a hacker writes a malicious code, will it infect all the nodes as every node will run a copy of it ? No, it won’t affect the node as Ethereum runs on Ethereum Virtual Machine (EVM) which is completely isolated thus keeping your main system secure.
Example : If a farmer and distributer want to trade, there might be several conditions to their contract but what if they don’t trust each other ? This issue is solved by Smart Contracts. So the farmer and the distributer will form a smart contract mentioning all their conditions for a successful transaction. Then they will connect their Contract account to the Smart Contract and now the Smart Contract is responsible to check whether both the parties have fulfilled their ends of the contract. If yes, it will automatically initiate the transaction which farmer and distributer agreed upon.
So why doesn’t Bitcoin allow hosting of smart contracts ? Bitcoin Script is a language on which Bitcoin chain is coded but this is Turing Incomplete language i.e. it doesn’t allow writing of loops to the code. The reason for not allowing loops was to avoid compromising the network to a hacker who might run an infinite loop to slow down the network. And without loops it is very hard to write any program or logic (also repeating the same code, a nightmare for programmers).
Then why does Ethereum allow this ? Solidity which is the language used to write Smart contracts on Ethereum chain is Turing complete language. But Vitalik thought of a crazy solution to this issue, every execution of a smart contract requires gas fees. This is a brilliant solution as it prevents unnecessary attacks as eventually the attack will stop after the balance in contract account exhausts. Let’s look more into Gas.
To understand Gas on Ethereum network you will need to understand this carefully. Gas is nothing but the amount required to run your smart contract on the ethereum chain. It is calculated as : Total Gas Units multiplied by Gas Price.
Every action that changes something on the chain requires gas, and every action has a certain amount of gas associated to it. This is calculated in units. Summation of total units of gas is then calculated to approximate the amount that would be required to host the contract, as you cannot keep manually calculating the number of gas units as the code base grows. The actual gas units required can only be determined by a miner.
Gas Price is a price that you are willing to pay per unit of gas. It is a choice of deployer but as you know it, the higher the gas, the faster the transaction.
Gas Limit is the limit on the number of units of gas to be used for a particular contract. You do not want your Contract account to be emptied only because of some bug in the code. So to safe guard your account, you give a limit of gas units, when the miner calculates the required gas units if it is within the limit the contract will be deployed otherwise not.
Example : You formed a contract which you calculated would take 10 gas units and you are willing to pay 10 Gwei per unit gas (1 Gwei = 10^-9 ETH, it is commonly used to calculate the Gas). So the total amount will be 10 units * 10 Gwei = 100 Gwei. So you set a limit of 11 units gas, if you encounter any bug or miscalculation this will cancel the deployment thus saving your balance.
What are smart contracts used for ? To deploy Decentralized Applications. Decentralized Applications is a mixture of Front-End (to make it user friendly) and Smart Contract (which acts as the back-end). These Dapps are used to provide user control over their data as no central authority can regulate the decisions. Moving on you can also create decentralized organizations.
As you know, the structure of an organization contains a hierarchy. Example: Director, Manager and Employee. This can be replicated using smart contracts where decisions are made by various If-Else blocks and voting. This is called Decentralized Autonomous Organization (DAO). Decentralized as the decision is finalized by voting and autonomous, because the smart contracts use logical blocks to derive a decision.
That’s it for this week! Stay tuned, Next Week : The DAO Attack, Hard and Soft Fork, Initial Coins Offering (ICO), Sharding and Alt Coins.
Source : Code Eater.