Demystifying Decentralized Applications and Smart Contracts

Introduction

As the blockchain revolution keeps raving, more developers and companies seek ways to learn about it and possibly adopt it for their next project. This article does not introduce the reader to what blockchain is or how it works. Instead, this article seeks to be more practical — teaching the reader about Decentralized Applications (DApps), why they are useful, and how their smart contract backends are built.

The reader is expected to have a computer close by with an internet connection, to practicalize the steps provided here. The tutorial is easy to follow, hence the reader must not be a developer prior to now.

The article is broken down into five parts as seen in the outline.

Outline

  • Understanding DApps
  • Advantages of DApps
  • Disadvantages of DApps
  • Popular DApps
  • Building a DApp
  • Final words

Understanding DApps

In order to clearly understand what DApps are, the concept of decentralization must be introduced. Apparently, all web applications in the Web2 ecosystem are run by a centralized body, even though they are open source. The servers hosting them are owned and maintained by an individual or a group or a company.

Centralized applications, as they are called, have been around for a long time, but they have their downsides. Some of these include:

  • they lack transparency.
  • they have a single point of failure.
  • they discourage censorship.

Given these downsides, the emergence of decentralized technology became imminent. This technology is the root of decentralized applications (DApps). It may be worth mentioning distributed applications. Distributed applications are those that are distributed across numerous servers rather than one.

DApps are web applications whose backend runs on a decentralized peer-to-peer (P2P) network, with an open-source code. DApps have different data structures, based on the functionality they were created for.

Advantages of DApps

DApps are advantageous in the following ways:

  • They have no single point of failure, hence are fault-tolerant by nature.
  • They are transparent, hence they are easy to trust.
  • The government, or any regulatory body, has no right or ability to remove content on the blockchain.

Disadvantages of DApps

DApps, like every other system, has disadvantages and they are listed below:

  • DApps are difficult to scale as every peer in the network must update their node software. They have to be built to scale right from scratch.
  • The absence of identity verification policies, such as KYC, due to the absence of centralized authority is an issue.
  • They have complex architecture due to their reliance on consensus mechanisms.
  • DApps may rely on each other, or on centralized applications.

Even before the explosion of Web3.0 in 2021, blockchain technology has been doing well and gaining wide applications. The most popular blockchains are listed below.

Bitcoin

Bitcoin is the most popular blockchain, the oldest, and the motivation behind every other one. It is a decentralized digital currency created in January 2009 by a mysterious individual or group under the pseudonym of Satoshi Nakamoto.

Ethereum

Ethereum is a decentralized platform on which DApps can run. These DApps are written with smart contracts, such that a DApp can consist of one or more smart contracts. On Ethereum, smart contracts

Smart contracts operate precisely as they are programmed to, with no chance of a crippled downtime, the violation of censorship, direct fraud, or third-party interference.

Solana

On the official project website), Solana is defined as thus:

“Solana is the fastest blockchain in the world and the fastest-growing ecosystem in crypto, with thousands of projects spanning Defi, NFTs, Web3, and more.

Cardano (ADA)

Cardano is another popular blockchain that builds upon the shortcomings of Ethereum and Bitcoin. Hence, it is often referred to as a third-generation blockchain. It operates on Proof of Stake consensus, unlike Bitcoin and Ethereum, so it is a more efficient solution.

Below is a list of popular DApps:

PancakeSwap

PancakeSwap is the most popular DApp in the Web3 world, built on the Binance Smart Chain (BSC). It charges lower fees for transactions especially because it is built on BSC. This makes it the most used DApp among its counterparts.

Uniswap

Uniswap tops decentralized exchanges (DEXs) on Ethereum, with more users than any other. It has over 300 applications in its ecosystem, paving the way for upcoming DEXs.

Aave Protocol

Aave protocol is the most diverse lending pool in the Ethereum ecosystem. It is an open-source and a unique, non-custodial liquidity protocol.

Building a DApp

DApps can be software applications or websites built on a decentralized network, such as Ethereum. Smart contracts are the backend code for DApps. Thus, a DApp is made up of a frontend integrated with a smart contract backend.

While the main language for building frontends of DApps is JavaScript, smart contracts are authored with any choice language from either general-purpose languages like Go, Rust, and Haskell, or contract-purpose languages like Solidity, Vyper, and Serpent.

Authoring smart contracts in Solidity

A smart contract is a piece of software controlled by code that is executed on the Ethereum Virtual Machine (EVM). They are not legal contracts, and neither are they smart. While smart contracts are written in the afore-mentioned high-level languages, they are compiled to low-level bytecode on the EVM.

A contract is identified by an Ethereum address which is used in transactions or to call one of the contract’s functions.

Since Web3 development is all about “writing money,” authoring smart contracts has to be done with extreme care, as bugs can be costly. Developers have to deliberate on each function as if writing modular code, in order to mitigate these costly mistakes.

Solidity is a language created by Dr. Gavin Wood specifically for the purpose of writing Ethereum-native contracts. It is maintained as an open-source project on GitHub.

To start developing Ethereum-native smart contracts, the latest version of the Solidity compiler should be downloaded.

Next, the Remix IDE is needed for writing, compiling, and deploying smart contracts. The Remix IDE can be accessed online or downloaded offline, as the developer sees fit.

Alternatively, the Solidity compiler can be installed on Node Package Manager (NPM) using the command npm install -g solc or on Docker using the command docker run ethereum/solc:stable —help.

To serve as an example, a simple smart contract will be created below using the online version of the Remix IDE. Follow these steps to recreate a smart contract and understand how they are authored:

  1. Navigate to the Remix IDE website on a browser.

  2. After the brief tour to the development environment, click the plus [+] icon to create a new workspace. The sidebar that appears before the FILE EXPLORE section contains three icons at the top:

  3. The first icon displays custom and pre-built source files and folders.

  4. Clicking the second icon displays the Compiler window, allowing the developer to select the language, the EVM version, and the compiler.
  5. Clicking the third icon displays the Deploy and Run window, allowing the developer to select the environment, the smart contract’s Ethereum address, Gas limit, and more.

REMIX IDE home.png

  1. Name the new workspace as first_contract, then click the file icon to create a Solidity source file called first_contract.sol.

create workspace and file.png

  1. Write the following code in the coding environment:
// SPDX-License-Identifier: MIT
pragma solidity >= 0.4.19 < 0.9.0;

// contract begins here and has same name as the source file
contract firstContract {
    uint private anInteger;
    function HelloWorld() public {
            anInteger = 5;
    }

    function GetValue() public view returns (uint) {
        return anInteger;
    }

    function SetValue(uint _value) public {
        anInteger = _value;
    }
}
  1. Click the Compiler icon and click Compile first_contract.sol.

first contract and compiler image.png

  1. When the Compiler finishes compiling the code, a green tick ✅ appears close to the Compiler icon.

  2. Move to the Deploy window. The Deploy button is ready for clicking, but given the rigid nature of smart contracts — i.e., they have to be built to scale from the scratch — a test has to be carried out. Blockchains have many public networks: the mainnet and other testnets.

Note: Only use the Deploy and Run window when you want to deploy an actual smart contract.

Final words

In a follow-up article, a complete creation and deployment of a Solidity smart contract will be taught. That article will cover how to connect to the Ethereum network, create an application and Ethereum address for the contract, and test on a Testnet.