Happy Employees == Happy ClientsCAREERS AT DEPT®
DEPT® Engineering Blogweb3

Demystifying Layer 2 solutions: Why you should consider them when building on Ethereum

With over one million transactions being processed per day, a new block is created every 12 to 14 seconds and Ethereum has now reached its present capacity on the network. This is where layer-2s jump in.

Making sure customers have a smooth and fun ride is a big deal for businesses, and that's no different in the world of blockchain. Though currently, the user experience often tends to lean disorganized and fragmented.

Your average Joe or Jane might feel overwhelmed by the complicated interfaces and may even require technical experience to simply understand what is actually happening. This combined with high fees and slow transaction times makes it difficult for businesses to provide customers with a seamless and cost-effective Web3 experience, ultimately impacting brand reputation and customer loyalty.

Whether you’re building a loyalty 3.0 program, developing an on-chain video game, or implementing crypto-micropayments in your business model, layer-2s may be the solution to making your projects work better and faster.

But before we dive into layer-2s, be sure to take time to grasp the basic ideas of blockchain and decentralized networks.

In a perfect world, blockchains would be totally decentralized, secure, and scalable.

Realistically, a blockchain can only have two of these three properties at a time. Vitalik Buterin, the co-founder of Ethereum, dubbed this the "blockchain trilemma." Ethereum’s fame is driven by its decentralized and security factors, but this comes at the cost of high transaction fees. If you’ve ever traded an NFT or engaged in DeFi protocols, chances are you paid a hefty fee.

The goal is to solve the trilemma without discarding decentralization, which is where layer-2s act as the hero solution. These scalability enablers come in all sorts of shapes and sizes, with the major categories being the so-called optimistic rollups and zk-rollups. For now, you can think of all these fancy terms as tools that make it possible for the Ethereum network to welcome more transactions without emptying your bank account.

How do they work?

Layer-2s are blockchains that sit on top of the base blockchain (e.g. Ethereum) — hence the word “layers.” They constantly communicate with the Ethereum chain by sending transactions. But how do they scale transactions?

Because transactions that demand high computational power also have higher fees, the solution is to refrain from doing these computations on the base chain. Instead, the computation of transactions can be done off-chain, meaning they are processed in a parallel blockchain: the layer-2.

In this case, the base chain provides the security features while the layer-2 does the majority of the work, enabling speedy and affordable transactions, plus the ability to handle a high volume of transactions per second. Then, multiple off-chain transactions can be combined into a single layer-1 transaction, massively reducing transaction fees.

Here’s a simple way to think of it: Picture 100 people trying to drive on a one-lane highway all in separate cars, at the same time. Traffic. Now imagine how much more efficient this scene would be if the cars were replaced by 10 buses carrying 10 people each.

In addition to increased efficiency, layer-2s also have the benefit of security. Layer-2s settle their transactions on Ethereum, which is already pretty secure as a network. Given these factors, it’s  much easier for businesses to start using the Ethereum network for projects when operating through layer-2s.

The need for Layer-2s

Transactions fees vary based on the level of demand on the network. As more users attempt to add their transactions to the upcoming base-network block, the cost of those transactions goes up. With over one million transactions being processed per day, a new block is created every 12 to 14 seconds and Ethereum has now reached its present capacity on the network. This is where layer-2s jump in.

Layer-2s work like a gadget that grabs a bunch of transactions and bundles them into one slick base-chain transaction. Then, the Ethereum fee gets divided up among all the players involved, sort of like how a group of people on a highway would split the cost of the bus. Currently, the most popular choice for scaling Ethereum using layer-2 solutions is called rollups. The two most common types of rollups are:

  • Optimistic
  • Zero-knowledge

While their functionalities are similar (computation is performed off-chain and transactions are bundled in a bag), they differ in their approaches to validating transactions. This enables different benefits such as withdrawal speed or transaction latency.

Comparing optimistic rollups and zero-knowledge rollups, the former is considered to be more user-friendly, cheaper, and simpler to program. However, it comes with a drawback of a delay in transaction finalization and relies on users to verify the accuracy of the transaction. On the other hand, zero-knowledge rollups offer immediate withdrawals and guarantee authenticity, but they come with higher costs and require clear cryptographic proof to function properly.

Optimistic rollups cover around 85% of the market (in terms of Total Value Locked) and include Optimism and Arbitrum. Some neat examples of zero-knowledge rollups are Polygon zkEVM, Starknet, zkSync Era, and Immutable X.

The Ethereum Virtual Machine (EVM) compatibility

Zero-knowledge rollups use different technologies to prove transactions (zkSNARKs, zkSTARKs), and some are compatible with the Ethereum Virtual Machine (EVM), which means they can run Ethereum smart contracts. Think of it like two people who speak the same language and can easily understand each other. This compatibility makes it easier for developers to create and deploy the same smart contracts on different EVM-based blockchains without making major changes to their code.

The Polygon zkEVM rollup aims to be EVM compatible so that Ethereum-based applications, tools, and infrastructure can be easily migrated to Polygon zkEVM with minimal changes. Polygon zkEVM can handle Solidity code directly, which is the most commonly used language for developing smart contracts on Ethereum. This means that almost all code from pre-existing EVM chains can be transferred to the new chain without needing to rewrite any code.

Similarly, zkSync Era is also EVM compatible and can accept EVM languages like Solidity, Vyper, and Yul. It uses its custom virtual machine to run the code, which makes it easy for developers to move their existing EVM smart contracts to zkSync Era without having to rewrite them in a different language or tool.

However, some rollups are not EVM compatible, like Starknet, which uses a unique programming language called Cairo. This means that you can't use the same language you would use for Ethereum on Starknet. Cairo was designed specifically to create Starknet programs to optimize the proving performance of each transaction execution. Transactions written in Cairo go through a transpiler that translates them to Solidity so Ethereum can understand the activity done on Starknet. This is like two people who speak different languages and require translation to understand one another.

What does this mean for you?

Layer-2 solutions are a critical tool for businesses looking to incorporate Web3 technology into their operations.

Visa, for example, has partnered with Starknet to enable customers to pay bills using their digital assets while maintaining control over them. This is possible due to account abstraction, a feature that treats every cryptocurrency account as a smart contract, eliminating the need for private keys, seed phrases, and other cumbersome security measures — ultimately resulting in a more user-friendly experience.

Layer-2s also improve the user experience for cryptocurrency traders by providing the comfort of Web2 apps with the security and decentralization of Web3 apps when handling digital financial assets. Decentralized exchanges like Uniswap and 1inch have deployed on Layer-2 solutions like Arbitrum, Polygon, and Optimism to offer transaction scaling and account abstraction.

Gaming is another industry that's rapidly adopting blockchain technology. Platforms like TreasureDAO enable developers to build games on Arbitrum, while games like Influence utilize Starknet's computing power to run on-chain. ImmutableX, a popular zk-Rollup for gaming platforms, has partnered with Starkware's StarkEx to reduce transaction costs and improve user experiences.

Layer-2 solutions are essential for any brand building on Ethereum, as they can help avoid issues like slow transactions, poor customer experiences, high development costs, and fluctuating transaction fees. Layer-2 solutions like Starknet and zkSync Era offer account abstraction features that can solve common DeFi problems like insufficient token balances and rejected smart contracts, making them a valuable tool for building successful projects and providing users with next-level experiences.

By embracing the power of Layer-2s, businesses can revolutionize their operations.