This is the 8th day of my participation in the First Challenge 2022. For details: First Challenge 2022.

When you talk about the Web 3.0 architecture, you usually mean DApps, which stands for decentralized applications. Historically, the Web 2.0 architecture consists of the most familiar components:

  • The front end: browser A client application retrieved from the host server and presented to the user. The current mainstream frameworks includeVue,React,Angular,EmberOr any other popular framework.
  • The back-end: server-side application, typically, one application takes over all the heavy logic, interacts with the client through an API, and is written in a popular back-end language:JAVA,NodeJs,C#,GO,Ruby,Python.
  • The database: it can beNoSQLSQLDatabase server, used to store all client and server data, the most popular database currently isPostgresql,Mongo.

Of course, there are many more components, depending on extensibility, but that is beyond the scope of this article.

Backend in Web 3.0 DApps

The main difference between DApps is that they are decentralized. There is no need for a centralized database or Web server and applications can be distributed across a network of computers using blockchain. The blockchain will act as a “state machine” to maintain program state and stability by validating predefined rules. The state machine is propagated among all participants in the blockchain network, and validation is archived through a common understanding of the program’s stability.

The back-end logic is implemented through smart contracts that are later deployed to shared state machines (blockchain networks). As a result, the back end resides in a peer-to-peer network, where everyone can contribute by matching certain criteria (for example, owning and locking cryptocurrencies in order to vote on changes or make recommendations to programs). Let’s take a look at how the front end works in a DApp.

Front-end in Web 3.0 DApps

The front-end architecture in DApps focuses on communication with smart contracts (decentralized programs), which is different from the common front-end to back-end communication. Each node in the blockchain network carries the state of the program, and in order to communicate with a smart contract, one of the nodes must be communicated, which could be:

  • Test nodes such as Infura, Alchemy, and Quicknode.
  • Or set up your own nodes by running your own state machine

Starting a blockchain infrastructure can be challenging, especially if you want to scale it to add more nodes. This is convenient when provided by the user, but the disadvantage is that it creates a centralized dependency component. All providers are implementing the JSON-RPC specification to communicate with blockchain networks. RPC, or remote procedure call, is a request-response protocol that defines rules that allow clients to send messages to remote machines to perform functions and retrieve responses. In such communication, the program runs on the client machine, which means that the client is unaware of the remote machine, and all communication takes place over HTTP or Web sockets.

When the provider connects to the blockchain, the client is able to obtain information about the state of the blockchain. But how does a client write to a blockchain network? All write request transactions need to be signed using the client’s private key, and each transaction is charged to the client for gas, a cryptocurrency that will be used to authenticate the other nodes of the transaction (miners).

Such providers, such as Metamask, act like transaction signers and providers. It stores the private key in a browser and signs it when a client makes a transaction request, and it is connected to a blockchain network.

Data layer in Web 3.0 DApps

Storing data in blockchain can be very expensive due to transaction gas fees and it makes more sense to use non-blockchain solutions such as IPFS or Swarm for point-to-point storage.

  • IPFS: A peer-to-peer file system protocol that allows data to be stored across a network of machines, using private or public network connections in the absence of native support from popular browsers.
  • Swarm: Similar to IPFT, with the only difference that the system is maintained through smart contracts in the Ethereum blockchain network.

To make the front end also decentralized, you can use the same point-to-point storage solution.

Finally, to simplify querying data stored in a blockchain or peer-to-peer network, you can use Graph, which converts GraphQL queries into smart contract events and peer-to-peer gateways.

conclusion

The Web 3.0 DApp architecture may seem pretty overwhelming, and it is, but there are more tools out there designed to simplify the build experience, such as Hardhat and ThirdWeb.