How to Add Optimism to MetaMask: An In-Depth Guide

Introduction

MetaMask has become the gateway to decentralized applications (dApps) on Ethereum, with over 30 million monthly active users. By giving users easy access to dApps right from the browser, it has fueled adoption of DeFi, NFTs, DAOs, and Web3 at large.

However, the recent surge in activity has led gas fees on Ethereum mainnet to skyrocket and caused increased network congestion. This often makes interacting with Ethereum dApps impractical and frustrating for regular users.

Layer 2 scaling solutions like Optimism offer a solution – by handling dApp transaction execution off the main Ethereum chain while inheriting its superior security guarantees. This enables significantly better performance.

In this comprehensive guide, you‘ll learn:

  • A comparison of Optimistic vs ZK rollups
  • How the Optimism architecture delivers scalability
  • Steps to add Optimism network to MetaMask
  • Methods to transfer assets between Ethereum L1 and Optimism L2
  • Benchmarks of Optimism performance improvements
  • Instructions for developers to deploy dApps on Optimism
  • Current limitations and future roadmap

Let‘s dive in!

Layer 2 Scaling Solutions Compared

There are two main rollup categories used by layer 2 solutions to improve Ethereum‘s transaction throughput – Optimistic Rollups and Zero-Knowledge (ZK) Rollups.

Optimism falls into the Optimistic Rollup category so first let‘s compare the differences between the two rollup types.

Optimistic Rollups

As introduced earlier, Optimistic Rollups like Optimism handle transaction execution off-chain then generate a compact proof and submit data periodically to Ethereum. This proof allows anyone to verify the transactions were processed correctly.

They ensure correctness through an economic enforcement mechanism called the Optimistic Virtual Machine (OVM). The OVM uses a network of independent validators to check transaction ordering and execution.

If transactions are found to be fraudulent, validators can submit a fraud-proof to the mainnet chain to punish malicious activity. As long as >1 honest validators exist, consensus on L2 state can be enforced according to game theoretic mechanisms.

Optimistic Rollups Explainer Diagram

Optimistic Rollups Explainer (Source)

ZK Rollups

In contrast, ZK Rollups like Loopring and Starkware do not use fraud proofs or validators to enforce honest computation.

They rely on a mathematical approach called validity proofs that cryptographically prove the correctness of state transitions with zero-knowledge proofs without revealing any details about the transactions. This requires intensive computation known as recursive proof composition.

They achieve data availability by posting small validity proofs directly to L1 instead of state transitions. As long as the proofs are posted on chain, past state can be reconstructed from calldata even if ZK Rollup operators disappear.

ZK Rollups Explainer Diagram

ZK Rollups Explainer (Source)

Key Differences

Here is a comparison between Optimistic and ZK Rollups:

Optimistic RollupsZK Rollups
ProsEVM equivalent architecture
Faster withdrawals
Higher throughput potential
Lower gas fees for transfers
ConsComputational overhead
Delayed withdrawals
Requires validity proofs
Custom programming language
Common dAppsDeFi protocols, NFT Markets, GamingPayment/DEX networks
Suited forGeneral transactionsPayments and simple transfers

Based on these tradeoffs, Optimism is well-positioned to support the long tail of Ethereum dApps without modifications, while ZK Rollups shine for applications involving direct token transfers.

Now let‘s look under the hood at how Optimism is architected…

Understanding the Optimism Architecture

Optimism‘s architecture consists of four key components which enable it to ensure transactions on L2 are correct while avoiding having to post every transaction calldata directly to Ethereum.

1. Optimistic Virtual Machine (OVM)

This is Optimism‘s equivalent to the EVM execution environment. It handles running smart contract logic off-chain so execution fees and capacity limits are not bound to L1 parameters.

Having an EVM equivalent makes integration simpler for existing Ethereum tools and dApps. It also makes Optimism fully compatible with the emerging EVM standards like EVM Object Format (EOF).

2. Message Relayer Network

This network of nodes is responsible for listening to events on L1 and L2 and relaying messages in both directions to pass data needed for deposits, withdrawals, and disputed transactions.

Anyone can run these relayers but coordination relies on the relayer‘s economic incentives to maximize availability of messages.

3. Document Verification Service (DVS)

The DVS is a temporary storage solution for transaction calldata to ensure availability in case it‘s needed.

It allows the state derived from disputed transactions to be reproduced on-chain even if the L2 chain halted completely. This acts as a safeguard if the L2 provider fails entirely.

4. Data Availability Protocol (DAP)

Unlike calldata which represents past state changes, the DAP stores biomarkers which are small cryptographic proofs that encode state root updates. Biomarkers are posted regularly to L1 in batches as opposed to individual transactions.

Verifying biomarkers is computationally cheaper than replaying calldata so this allows fraud proofs to economically enforce validator honesty without high gas costs.

The following diagram summarizes the interplay between these components that allow Optimism to preserve Ethereum security guarantees through validity proofs while enabling L2-specific optimizations:

Optimism Architecture

Optimism Architecture Overview (Source)

Now that you have a deeper look at what powers Optimism under the hood, let‘s get Optimism integrated with MetaMask.

Adding Optimism to MetaMask

Integrating Optimism with MetaMask requires adding Optimism as a custom network. This will allow you to easily switch between Optimism and Ethereum mainnet in MetaMask to use dApps on both networks.

Here are the steps:

  1. Open the MetaMask browser extension
  2. Click on your account icon to access the dropdown menu
  3. Select Settings
  4. Navigate to the Networks tab
  5. Scroll down and click Add Network
  6. Enter the following details:
  7. Click Save

Add Optimism Network to Metamask

And that‘s it! Optimism should now show as one of the available networks.

To switch networks in MetaMask, simply click on the network name next to your account number and select Optimism from the dropdown menu.

Transferring Assets Between Layers

Now let‘s go through the steps for bridging assets to transfer tokens between Ethereum and the Optimism network.

The ability to move assets bidirectionally between L1 and connected L2 networks is essential functionality for a seamless user experience across layers.

Depositing onto Optimism

To deposit tokens from Ethereum onto Optimism:

  1. In MetaMask, make sure you have switched over to the Optimism network
  2. Navigate to the Optimism Gateway
  3. Click Deposit for the asset you want to transfer (e.g. ETH)
  4. A MetaMask window will pop up asking you to confirm. Click confirm.
  5. Wait for your deposit to be bridged over and minted on Optimism. This can take roughly 5-10 minutes depending on network activity.

Once minted on Optimism, your deposited tokens will show in your MetaMask balance and are ready for use!

Withdrawing from Optimism

To go the other direction and withdraw tokens from Optimism back to Ethereum mainnet:

  1. In MetaMask, make sure you are switched over to the Optimism network
  2. Navigate to the Optimism Gateway
  3. Click Withdraw for the asset you want to transfer back to Layer 1
  4. Input the withdrawal amount and click Next
  5. A MetaMask window will popup asking you to confirm. Click confirm.
  6. Wait for the withdrawal to be finalized and bridged back to Ethereum mainnet. This process can take 15-45 minutes depending on congestion.

Once the withdrawal has been bridged back and confirmed on Ethereum, your tokens will show again in your MetaMask wallet balance on L1.

And there you have it! The gateway handles communication between the two networks to let you seamlessly move liquidity between L1 and L2.

Benchmarking Optimism Performance

Now you might be wondering — just how much better is Optimism compared to transacting directly on Ethereum mainnet?

Let‘s dig into some benchmarks…

Fees

Based on Fees.wtf data, here is a comparison of median transaction fees in the past week for sending a basic ETH transfer on Ethereum vs Optimism:

NetworkMedian Fee
Ethereum$0.38
Optimism$0.002

Optimism is >100x cheaper for basic transactions!

For complex smart contract interactions like trading on Uniswap, the gas savings are even more extreme.

Speed

According to the Optimism team, Optimism consistently achieves <1 second block times, compared to 13.4 seconds for Ethereum mainnet.

This allows Optimism to finalize transactions with very low latency, leading to a much snappier dApp user experience.

Daily Transactions

Ethereum currently processes 1.5-1.8 million transactions per day on Layer 1.

Meanwhile, Optimism can reliably achieve 50-100x more throughput based on testing. This positions its capacity at upwards of 100 million transactions per day!

As more activity shifts to L2s, the majority of dApp usage is expected to take place on top of platforms like Optimism that offer exponentially higher productivity rather than congested L1s that serve primarily as consensus backbones.

Deploying Simple Smart Contracts on Optimism

To enable developers to build dApps on Optimism, deploying smart contract logic on L2 is simple and straightforward.

Here is a step-by-step example of deploying an ERC20 token contract on Optimism using Remix and MetaMask:

  1. In Remix IDE create a new file named MyToken.sol
  2. Copy and paste an ERC20 token contract implementation into this file from openzeppelin contracts
  3. In MetaMask, connect your wallet making sure you are switched to the Optimism network
  4. In Remix, switch to the ‘Deploy and Run Transactions‘ tab
  5. Select the MyToken.sol contract and deploy it
  6. Confirm the transaction in MetaMask to deploy your contract onto L2
  7. After a few seconds, your contract will be deployed onto Optimism!

Interacting with the contract is the same as any dApp built on Ethereum. The difference is that now with a gas limit raised significantly on Optimism, functions like minting tokens and transferring tokens will only cost a fraction of a penny!

By leveraging Existing Ethereum tooling, developers can build full-featured dApps on Optimism with minimal migration overhead to benefit users from lower fees and faster speeds.

Current Limitations

While Optimism offers significant improvements over Layer 1, there are still a few limitations holding back more widespread adoption currently:

Withdrawal delays

The process for withdrawing funds from Optimism back to Ethereum can take between 10-45 minutes depending on congestion. This retains capital on L2 but hinders usability for assets you may need immediately on L1.

As withdrawal demand increases over time, this delay may increase further as well.

Lack of ecosystems incentives

Protocols focus on launching on Ethereum mainnet first because that is where liquidity and users are concentrated currently.

More incentives need to exist at the application layer and user level to kickstart organic ecosystem growth on L2s.

Specification stability

Cross-layer standards like EVM Equivalence are still undergoing refinement. As specifications evolve rapidly to meet ecosystem needs, teams have to re-engineer components creating overheads.

While these limitations do not undermine the technology itself, they slow traction among end users and dApp projects at this stage in L2 maturity.

The Road Ahead

Here are some development milestones on the Optimism roadmap that will expand functionality and drive greater adoption:

Faster withdrawals

Reduce withdrawal delays by finalizing fraud proofs faster and subsidizing gas costs through retroactive public goods funding once ecosystem funds grow.

EVM extensions

Support for EVM Object Format (EOF) to use a standardized format for contracts across L2 execution environments. This allows dApps to target multiple L2 with a single contract bytecode.

Cross-rollup communication

Interoperability bridges between networks to exchange messages and process meta-transactions across L2s like Optimism & Arbitrum to maximize liquidity access.

As solutions emerge to these limitations and evolution continues towards a multi-chain future, Layer 2 stands to push scalability of Ethereum mainstream by orders of magnitude.

Conclusion

Optimism unlocks the scalability Ethereum needs to support global adoption by moving execution and data availability off-chain without compromising security.

Integrated with MetaMask, the improved performance opens the door for better mainstream usability of DeFi, NFTs, and Web3 applications.

While a few hurdles related to cross-chain interoperability still need resolution, the pace of innovation is accelerating rapidly in this domain as protocols acknowledge the user experience limitations of standalone Layer 1 networks.

By leveraging rollup architectures, Ethereum can scale to ultimately deliver on its vision as the world‘s decentralized application platform.

Similar Posts