Open In App

Architecture of a dApp

The architecture of dApp or Decentralized applications is quite different from traditional applications. Decentralized applications require a unique system design to achieve high security, reliability, and privacy.

In decentralized applications, there’s no centralized database that stores the application state. It means, unlike centralized applications the client-side application does not communicate to the database instead it communicates directly to the blockchain.



Introduction to Decentralized Application(DApp)

A decentralized application is an application built on a decentralized network that combines a smart contract and a front-end user interface. It is a type of distributed open-source software application that runs on a peer-to-peer blockchain network. The use of blockchain in dApps allows them to process data through distributed networks and execute transactions.

dApp Architecture

Below are the components of the dApp architecture:



The following diagram shows what the actual architecture of DApp looks like:

 

Let’s discuss the components in detail:

1. Ethereum blockchain: Ethereum is a decentralized and open-source blockchain platform that establishes a peer-to-peer network that securely executes and verifies application code, called smart contracts. Decentralized applications have their backend code (smart contracts) running on a decentralized network and not a centralized server. DApps use the Ethereum blockchain for data storage.

2. Smart Contracts: DApps use smart contracts to define the state changes happening on the blockchain. A smart contract is a collection of code and data that resides at a specific address on the Ethereum Blockchain and runs on the Ethereum blockchain. They are written in high-level languages such as Solidity and Vyper.




// Example of smart contract in 
// decentralized application
  
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
  
contract Migrations 
{
  address public owner = msg.sender;
  uint public last_completed_migration;
  
  modifier restricted() 
  {
    require(
      msg.sender == owner,
      "This function is restricted to the contract's owner"
    );
    _;
  }
  
  function setCompleted(uint completed) public restricted 
  {
    last_completed_migration = completed;
  }
}

3. Ethereum Virtual Machine(EVM): The Ethereum Virtual Machine is the global virtual computer that executes the logic defined in the smart contracts and processes the state changes that happen on this Ethereum network.

4. Front-end: The front-end is the part of the DApps users can see and interact with such as the graphical user interface(GUI), but the front-end also communicates with the application logic defined in smart contracts.

Communication Between Frontend And Smart Contract On Ethereum

To invoke functions the front end needs to communicate with smart contracts. But Ethereum is a decentralized network. Every node in the Ethereum network keeps a copy of all states on the Ethereum Virtual machine, including the data and code associated with every smart contract.

It is required to interact with one of these nodes to interact with the data and the code on the blockchain. This is because any node can broadcast a request for a transaction to be executed on the EVM. Then the job of a miner is to execute the transaction and propagate the resulting state change to the network. The transaction can be broadcasted in two ways:

  1. Set up the node which runs the Ethereum blockchain software.
  2. Use nodes provided by third-party services.

Why Use Third-party Services?

When third-party services are used there is no need to run a full node yourself. Setting up a new Ethereum node on the server can take much time. Moreover, more nodes need to be added to expand your infrastructure and the cost of storing the full Ethereum blockchain goes up as DApp scales.
The nodes one connects with to interact with the blockchain are often called “providers.”

 

 

The role of Metamask in Dapp Architecture:-

 


Article Tags :