The Web3 development stack
Written by Kingsley Arinze
Before you set out to build an application, you need to first decide on the technology stack to use. The term “technology stack” refers to the tools, libraries, and frameworks needed to build and run a software application. A simple application would consist of three layers:
- The Data layer that handles information storage for easy retrieval and computation.
- The Logic layer that handles the business logic. All the necessary computation happens here.
- The Presentation Layer that is responsible for what the user sees. It presents everything happening under the hood in a user-friendly way.
To successfully build out each layer, you need to use specific tools, libraries, and frameworks. These tools, libraries, and frameworks are what forms your development stack for that software application.
In the traditional Web2 world, you hear references such as MEAN stack, LAMP stack, MAMP stack. These are all acronyms for some of the tools, libraries, and frameworks that power Web2 applications.
Web3 is an emergent iteration of the World Wide Web. As with every technology in its nascent stage, most people struggle to understand how the different parts come together. This blog defines the Web3 stack, but before we jump right in, let's review the evolution of the Web.
Web 1: Read-Only¶
Web1 was a read-only web and lasted between 1990 and 2004, with most users consuming content created by content creators.
The Web1 stack had two defining layers:
- File System for file storage (Data Layer)
- HTML and CSS for presentation. (Presentation Layer)
Since Web1 was primarily static and presentational, there wasn't a layer that handled business logic.
Web 2: Read-Write¶
The Web2 is a read-write web where both companies and users can be content creators. It allowed everyday people to contribute to the web for the first time and was ushered in by the Facebooks and the Googles of the world - the tech giants.
The Web2 stack can be said to include the following:
- Databases: Relational databases(Postgres, Mysql), NoSQL databases(MongoDB), and key-value databases(Redis), amongst others, form the data layer for Web2 applications.
Thus far, we've experienced Web1 where companies created content and, as a result, earned money. We've also seen (and are still seeing) Web2 where users generate content but only companies and platform owners, through user-generated content, make money. This new web iteration known as Web3 takes the web a step further by allowing content creators to own not only their content but their identity and assets.
Web3 is a decentralized, open, and censorship-resistant web, powered by blockchains like Ethereum, Solana, and hundreds of others. It is a trustless and self-governing web, where companies do not have as much power as they do in Web2 due to the openness and ownership of user data. Instead, it aims to return power to those responsible for keeping the network alive.
To explain what it means for users to own their data in Web3, let's examine the current situation on Web2 today. Assuming a user isn't impressed with the practices of a company they use regularly and decides to move to a different platform, this user would have to start fresh as all their existing data would live in a centralized database owned by a company like Google, Facebook, Amazon, and others. What makes Web3 different is that anyone with an Internet connection can access the blockchain which gives users more freedom and control over their data.
Web3 also introduced the concept of Decentralized Autonomous Organizations (DAOs), which is a new way of running companies through communities. In a traditional Web2 company, decisions regarding its direction are determined by investors and stakeholders, leaving out users directly affected by these decisions. With DAOs, users in the form of community members are responsible for deciding the direction of these companies through rules and regulations written in code and enforced by blockchain technologies. These programmable rules and regulations are known as smart contracts.
Smart contracts are computer programs that digitize agreements and automatically execute when the terms of said agreements are met. They are computer code that lives and runs on Ethereum and other blockchains.
The Web3 Stack¶
Web3 also introduces new primitives like native payment support that completely removes the need for intermediaries and large banks.
We can breakdown the Web3 stack into the following layers:
- The data layer powered by decentralized blockchain technologies
- File storage layer powered by distributed peer-2-peer networks
- API/Data Access Layer
- Presentation Layer
- Identity Layer
The data layer¶
This is where information is stored and is the major difference between the Web2 and the Web3 stack.
Whereas Web2 applications store data on central databases, owned and maintained by companies who restrict access, Web3 applications rely on open, decentralized, and permissionless state machines for data storage, where anyone with the requisite skills and enough curiosity can access data.
Blockchain technologies primarily power this layer and Ethereum is at the forefront with the majority of Web3 developers choosing to build their dapps there. Ethereum has a virtual environment known as the Ethereum Virtual Machine or EVM that stores user data (like accounts and accounts balance) and computes the next state of the network. This virtual environment is also responsible for storing and executing smart contract code mostly written in the Solidity and Viper programming languages.
Due to the popularity of the EVM and the Ethereum blockchain, we've seen the emergence of other blockchains, sidechains, and Layer 2 solutions fully compatible with the EVM, allowing applications built on Ethereum to run on these platforms without needing any modification. Examples of these platforms are:
- The Arbitrium layer two solution
- The Optimism layer two solution
- The Polygon sidechain
- The Avalanche blockchain
- The Fantom blockchain
There are other blockchains that operate differently from Ethereum and are not EVM-compatible but are home to decentralized applications too like Solana, NEAR, Avalanche, and others Although to build dapps on Solana and NEAR, you must understand the Rust programming language.
File storage Layer¶
Since users' data storage happens on decentralized blockchains, it makes sense that files like images, videos, HTML, and CSS files are also stored in decentralized networks so no one organization has full access and control over them. Unfortunately, storing data like the ones mentioned above on blockchains like Ethereum (and other EVM compatible ones) or Solana can be costly.
When choosing a data storage mechanism for a dapps, one has to consider the following:
- Persistence mechanism and incentive structure
- Data retention enforcement
Fortunately, there are several options to choose from like Arweave who offer permanent file storage by incentivizing node operators and miners who in turn maintain storage of these files for extended periods.
Contract-based platforms like Filecoin and Skynet do not store files forever but instead, keep files for a period specified by a contract. InterPlanetary File System or IPFS, another distributed system for storing and accessing files, doesn't have any built-in incentive mechanism for miners but can be used together with other contract-based solutions.
API/Data Access Layer¶
Another essential layer of the Web3 stack is the API or Data access layer. This comprises platforms that enable easy access to data that lives on the blockchain and files on distributed file storage networks.
Due to the current state of popular blockchain networks like Ethereum, running a self-hosted node to access blockchain data can be time-consuming. Therefore, maintaining these nodes does not contribute directly to productive hours, especially during development.
This is why platforms like Infura exist. Infura exposes a set of APIs that allow Web3 developers to connect their dapps to the Ethereum network with zero stress, letting them focus on building out application features rather than maintaining nodes. It also provides an API for connecting to IPFS for distributed files storage and retrieval.
Alchemy is another example of API platforms supporting popular blockchains like Ethereum, Flow, and Polygon. Quicknode, on the other hand, provides Dapps developers with access to blockchain data via APIs and dedicated node instances.
The presentation layer for a dapp is not too different from that of a Web2 app. We use the same set of libraries to create user interfaces. For example, due to its popularity and thriving ecosystem, the React.js library remains the preferred choice for building out the frontend of Web3 applications. Other libraries such as JQuery, Angular and VueJS can also be used.
The major difference between the Web3. frontend stack and that of Web2. is how we fetch data from external APIs. By comparison, a typical Web2 application uses HTTP libraries like Axios and Fetch to query API endpoints or clients like Apollo for GraphQL endpoints; in Web3, we use libraries like Ether.js or Web3.js to make Remote Procedure Calls (RPC) to blockchain nodes.
Unlike in Web2, where internet users are identified by their unique username/email and password, Web3 implements an entirely different strategy for identity management powered by blockchain wallet like MetaMask.
In Web3, the typical user experience involves connecting your wallet to a dapp you want to use and granting this wallet the power to sign transactions on your behalf. There are two popular ways to connect a wallet to a dapp:
- By accessing the provider object exposed by these wallets on the browser window. This primarily applies to wallets in the form of browser extensions.
- By scanning a barcode exposed by the dapp using tools like WalletConnect (for Ethereum). Wallets in the form of mobile applications mostly use this method.
Web3 enforces the concept of decentralization by replacing centralized technologies with blockchains and protocols. It also introduces a new way of giving users ownership of their data and identity through private-key cryptography. What will define Web3 moving forward is the ease at which dapps can be built. This is why defining the stack is critical. At Truffle we aim to be the number one choice for development.