Developing on The Ethereum Blockchain

Table of Contents

  • Introduction
  • Table of Contents
  • What is Ethereum?
  • Procedure for Building Smart Contracts
  • The Ether and the Gas
  • Computing on Ethereum
    • Testnets and Mainnet
    • Transactions on the Ethereum Blockchain
    • Types of Ethereum Network
  • Interacting with the Ethereum Blockchain
  • The Problem with Ethereum
  • The Coming of Ethereum 2.0

What is Ethereum?

Ethereum is the first blockchain to allow developers to build smart contracts. Vitalik Buterin proposed it in 2013. As an open-source project, it is a platform that allows anyone to build separate or related software with it. Ethereum came after the Bitcoin blockchain; hence it makes on the weaknesses and cons of Bitcoin.

For example, the transaction time on the Ethereum chain is in seconds instead of minutes on the Bitcoin chain. Also, while Bitcoin adopts the Proof-of-Work consensus mechanism, which is resource-inefficient, Ethereum is tethered towards the Proof-of-Stake tool.

The Solidity programming language is a Turing complete language that allows developers to program on the Ethereum blockchain. Developers new to Blockchain development are strongly advised to get started with Ethereum.

  1. There is a healthy community for Ethereum/Solidity, making it easier and cheaper to get open-source tools and resources.
  2. Ethereum builds on the weak points of Bitcoin.
  3. Ethereum allows developers to create smart contracts that they need, with an easy-to-use contract-purpose language.
  4. Ethereum has a wide adoption among commercial vendors and companies.

The Ethereum blockchain has a popular cryptocurrency named Eth (or eth), which is used to buy gas for smart contract deployment. Eth can be purchased and held like a regular cryptocurrency.

Procedure for Building Smart Contracts

EVM programs, otherwise called smart contracts, are pieces of the code that lives on the blockchain and execute specific action as they were programmed to. They can read other contracts, make decisions, send ether, and execute other smart contracts.

The lifecycle of a smart contract on the Ethereum blockchain include:

  1. Writing the smart contract logic in Solidity.
  2. Compile Solidity source code to bytecode
  3. Deploy on a testnet for testing
  4. Deploy on a mainnet for live production

The Ether and the Gas

A smart contract can run just a millisecond, or it can run forever. In any case, it must serve its purpose, without consuming unnecessary amounts of resources, compute time, and memory space. Ethereum makes use of gas to meter the lifespan of smart contracts on the chain.

As stated earlier, smart contracts live on the blockchain. As such, they will become indelible after they are deployed. It is made to run on gas bought by ether to stop smart contracts from running forever. The Ethereum Virtual Machine terminates the runtime of a smart contract once it runs out of gas.

Gas is acquired with Ether. The gas fee is specified during the deployment phase of the smart contract, the purchase price is earmarked along with the transaction.

The computation is executed by the EVM, and any unused gas is refunded.

Computing on Ethereum

The Ethereum Virtual Machine

The Ethereum Virtual Machine (EVM) is the stack-based virtual environment that compiles Ethereum smart contracts to bytecode for execution. Every node on the Ethereum network executes transactions using the EVM. Transactions are processed by the EVM.

The EVM is otherwise called a state machine. It stores state transitions locally on each node as a database. The database contains transactions and states in the form of a serialized hashed data structure called a Merkle Patricia Tree.

Testnets and Mainnets

Following the principles of Test Driven Development, testing Ethereum smart contracts before deploying them is important. Also, for developers who are just practicing building smart contracts, it is convenient to have a way of running practice smart contracts that are probably not going to make it to production.

Ethereum uses the concept of Testnets to provide fake Ether to pay for gas fees. Testnets only accept fake Ether from faucets. Examples of these are:

  • Ropsten Testnet
  • Kovan Testnet
  • Rinkeby Testnet

We will see how these are created and how free Ether is gotten.

Mainnet is the opposite of Testnets — it is the main Ethereum network. Smart contracts are deployed on the mainnet using real Ether. It is advisable to only deploy contracts to the mainnet when you are experienced enough and have a properly built smart contract.

For now, you will learn how to get test Ether for deployment in Testnets.

Transactions on the Ethereum Blockchain

Ethereum transactions are network messages on Ethereum that are made up of four major components:

  • Recipient
  • Signature
  • Value payload
  • Store

A transaction is dependent on the nature of the decentralized application. For example, in a Social Media DApp, a transaction can be uploading a picture or sending a message to a friend.

Types of Ethereum Networks

Ethereum networks exist in different kinds. The following are types of Ethereum networks:

Public Network

In public Ethereum networks, anybody can access the constituents of the blockchain.

Consortium

The Consortium networks allow access to some functionalities to just a group of organizations.

Private

A single organization can create a private Ethereum network usually to test Ethereum dApps before they are released to the other kinds of networks.

Interacting with the Ethereum Blockchain

In order to interact with the Ethereum blockchain as a user, you will need an Ethereum wallet. The Ethereum wallet is different from a traditional bank account in that it does not store your name. What the wallet does is generate a private and public key, and generates a wallet address that you can use to send and receive Ethereum.

Essentially, the wallet is just a key and address store. It uses the keys to sign transactions on the Ethereum blockchain.

Ethereum has different implementations as client applications. The following are examples of ways to interact with the Ethereum blockchain.

  • Your local terminal
  • Desktop or mobile applications
  • Browsers

Just like a bank account statement, your Ethereum wallet does not store your Ethereum cryptocurrency. Instead, it helps you manage your Ethereum account.

To get an Ethereum account, you will need to use Metamask or its alternative. Metamask is more like a browser extension, but it provisions you with a wallet address and helps you in smart contract development.

On your preferred browser, download and install the Metamask extension from the original website. After this, create a wallet and store the secret phrase and your private key.

To get test Ether, you simply have to switch to a test network on your Metamask extension, visit a faucet supported for that test network, and fulfill the requirements to gain test Ether from them. The requirements can be nothing or a simple social media post about your request. A popular website to get faucets with relative ease is faucet.metamask.io.

There is a donate option on every faucet website that allows you to test your Ether by sending a small amount back via Metamask and refunding unused Ether back to the faucet.

A Blockchain Development Suite

You can develop Ethereum contracts remotely, or locally with the use of Ethereum development Suites. You can find these suits by going to the developer section on the Ethereum Official website and selecting your preferred suite depending on your choice of languages.

Solidity is a high-level language that requires being compiled to bytecode (machine language). Using a development suite allows you to compile a Solidity source code to bytecode with just one command. You can learn more about Solidity from the link below.

Installing Hardhat

Hardhat has support for Typescript and Solidity languages. You can learn more about Hardhat here, but here is a simple installation for a Linux machine.

  1. Run system update:
$ sudo apt update
  1. Install Hardhat via node:
$ npm install hardhat --save-dev
  1. Code Editor

Visual Studio Code is a good Code Editor that allows the installation of various extensions to make the development process easier and more efficient.

Testing the Hardhat Suite with a Simple Smart Contract

We will write a simple Solidity smart contract in this sub-section and compile it to bytecode. We will create a smart contract on Hardhat to give you a feel of how to develop on Hardhat.

On your terminal, navigate to a new project repository and run the command:

$ npx hardhat

This command initializes the new project window for Hardhat. Select Create a simple basic project. Allow installation of all dependencies. Open the new project repository on your Code Editor after all installation is completed. You will see a Contracts package with a Greeter.sol Solidity file there.

Run the following command in your terminal:

$ npx hardhat compile

You should see an output like this:

npx compiled.png

You will also see two new folders: cache and artifacts. Congratulations, you just compiled a Solidity source code locally.

Why Learn Blockchain Development with Ethereum

Blockchain development is a fairly new field in the tech ecosystem. When learning a new technology, it is important to consider the market demand for that technology, and the community support or availability of learning materials for it. Blockchain technology has a steep learning curve as the entire concept is a set of different fields like computer programming, cryptography, economics, distributed systems, networking, mathematics, etc.

Ethereum has a huge market demand as the most sought-after are Solidity Blockchain engineers. Also, there is a huge support for Ethereum development with a lot of resources customized for it. Ethereum is a developer-oriented blockchain built by developers for developers.

If you enjoyed this, check out more similar articles in the archive.