Analysis of Ethereum Blockchain for Beginners.
Blockchain Evolution: —
It is now said,
“Blockchain is not a use case of the internet like email or SNS, but it is as parallel as the internet”.
The primary application of the first-generation blockchain network (introduced in 2008 by Satoshi Nakamoto) was the cryptocurrency using Bitcoin. Its popularity grew and the concept of blockchain became one of the hottest topics for developers. With an increase in research, the developer community proposed several enhancements to the protocol. In 2013, Vitalik Buterin proposed the second generation of blockchain called Ethereum. He proposed that a blockchain network can be used to develop different types of applications, and not only limited to cryptocurrency.
As the yellow paper says, “Ethereum is a transaction-based ‘state’ machine; a technology on which all transaction-based state machine concepts may be built”.
Ethereum: —
Within a few years, Ethereum became the largest open software platform as well as a programming language that helps developers to build and publish distributed applications, including the cryptocurrency.
It is programmable and allows the development of decentralized blockchain applications (i.e, the platform is not owned by any central authority) through the use of smart contracts. Users can signup for the platform, create an account, and deploy smart contracts to build decentralized applications.
The important characteristics of the Ethereum platform are -
1.EVM: The Ethereum Virtual Machine(EVM) is the runtime environment for smart contracts and is a powerful, sandboxed virtual stack embedded within each full Ethereum node, responsible for executing contract bytecode. Contracts are written in high-level languages, like Solidity, which is then compiled to EVM bytecode. Every node in the Ethereum network runs an EVM instance which allows them to agree on executing the same instructions. Any operation in the EVM consumes CPU cycles, disk access, memory, of the hosting machine, and a fee paid by ‘gas’(described later).
2.Accounts: Users can have 2 types of accounts — Externally Owned Account(EOA) and Contract accounts. The EOA is controlled by the users and has an ether balance and public-private key pair (a JSON key file) associated with it. The contract accounts are associated with the contract code and deployed EVM code which is stored in a smart contract referred to as smart wallets.
3.Block: The transactions in a blockchain network are bundled into blocks and executed across all the participating nodes. A block contains a transaction list, the most recent list, a block number, and a difficulty value.
4.Transaction: Each transaction includes the address of the recipient, transaction data payload, and transaction value. The transactions are signed by the sender’s private key. The total transaction cost is calculated by the gas used * gas price.
5.Mining: The transactions are verified using mining. A valid block contains proof-of-work(called Ethash in Ethereum) of a given difficulty. It is a competitive activity that miners undertake to write transactions to a new block that will be added to the blockchain. A miner successfully mines a new block while competing with fellow miners by running a hashing script and validate them and earn rewards in ethers.
6.Gas: Gas is the name of the crypto-fuel or the internal pricing which is consumed for performing the operations and the transactions on Ethereum. Every operation consumes some amount of gas. In another way, it is the fees paid to the network.
7.Smart Contracts: A smart contract contains a set of executable functions and state variables. The function codes are executed when transactions are sent to the function and execution results in a change of state variables. They are written in a high-level language called Solidity (generally). A solidity compiler compiles it and once compiled it uploads to the network and a unique address is given to it. It can be written for several purposes like exchanging money, property, shares, or anything of value in a transparent. It is the conflict-free way of avoiding the services of a middleman.
8. Decentralized applications: It is an application that uses a smart contract. It provides a user-friendly interface. It consists of files for a web-surface interface like HTML, Javascript, etc. There are “decentralized AppStore” where anyone can publish their apps ( called the dapps), unlike today’s apps (like Google Play) because they don’t require a middleman to function or to manage a user’s information. Go to BlockStack or Dapp Store for exploring the amazing world of Dapps.
9.Ethereum clients: With the help of them we can participate in the ethereum network and perform our tasks. Ethereum supports clients of a wide variety of languages like Go (geth), C++ (cpp-ethereum), Python(pyethapp), etc.
10.Ethereum Metamask: The Metamask Chrome Extension is the most popular and an excellent GUI for maintaining ether accounts and is available as a chrome extension. It allows us to connect to our local Ethereum blockchain with our account and interact with our smart contract. For more information head to Metamask.
11.Dapp Frameworks- Truffle: Pre-built frameworks like Truffle suite simplify the steps involved in the creation of Dapps. Truffle is a one-stop solution for building DApps which allows functions from compiling contracts, deploying contracts, injecting it into a web app, creating front-end for DApps, to testing. For further learning head to — Truffle suite.
a. Truffle has a built-in smart contract compilation, linking, deployment, and network management for public and private contracts. It can be installed by — npm install -g truffle.
Trending Cryptocurrency Hub Articles:
1. Is Groestle Coin The Next Digital Gold?!
2. Krypton Capital Invests in Gladius — Will Help with Product Development and Market Expansion
3. 3 ICOs with Working Products Already Being Used by the Public
b. Ganache is a personal, local in-memory Ethereum Blockchain used to run, test, and deploy smart contracts and perform introspection of contract data and other events free of cost. It will give us several accounts with addresses on our local blockchain and each account preloaded with fake ether to use.
c. Drizzle is a collection of front-end libraries that make writing front-ends easier. The core of Drizzle is based on a Redux store and spectacular development tools around Redux.
12.Web3 Javascript API: web3.js is a collection of libraries that allow us to interact with a local or remote ethereum node, using an HTTP or IPC connection. This API contains various objects that ease our interaction with the Dapp and network. Install by — npm install web3.
The structure of smart contracts: —
1.Contract class: Every code of smart contract begins with the contract class and contains a constructor which is must to be executed once.
2.State Variables: They are used to maintain the contract’s state.
3.Functions: They include the code which will be executed when the transaction is executed.
4.Modifiers: They check the conditions before the execution of a function and hence can change the behaviors of the functions.
5.Events: They are used to track the execution of the transactions in the contract class.
Example of a smart contract — The Document Verification:
This smart contract is used to store a cryptographic hash of any document, which is can be used to verify and validate the same, on the blockchain network. The hash of the document, the timestamp of submission, and the address of the owner are submitted to the smart contract. The cryptographic hash is based on the content and hence any attack changing the content will result in a change of the hash. Thus users can securely trust the document over the network.
The sample code is written in Solidity for the same —
Implementing Dapps :
After writing the Ethereum smart contract, we will deploy it to the Ethereum blockchain, and develop a client-side application that will allow accounts to post their data and talk to the smart contract. The best solution is to use the Truffle framework and Metamask browser extension. We can also use HTML, CSS, Bootstrap, Javascript for the creation of our client-side application.
For more details of how to create a dapp and deploy, I found this article extremely useful —