OP Mainnet
Testing
Running a Local Development Environment

Running a Local Development Environment

This tutorial teaches you how to setup and run a local development environment of the entire OP Mainnet system.

What is this?

A development environment is a local installation of the entire OP Mainnet system. Our default development environment includes both L1 and L2 development nodes. Running the OP Mainnet environment locally is a great way to test your code and see how your contracts will behave on OP Mainnet before you graduate to a testnet deployment (and eventually a mainnet deployment).

Alternatively, you can get a hosted development node from any of these providers.

Do I need this?

We generally recommend using the local development environment if your application falls into one of the following categories:

  1. You're building contracts on both OP Mainnet and Ethereum that need to interact with one another. The local development environment is a great way to quickly test interactions between L1 and L2. The OP Mainnet and test networks have a communication delay between L1 and L2 that can make testing slow during the early stages of development.

  2. You're building an application that might be subject to one of the few differences between Ethereum and OP Mainnet. Although OP Mainnet is EVM equivalent (opens in a new tab), it's not exactly the same as Ethereum. If you're building an application that might be subject to one of these differences, you should use the local development environment to double check that everything is running as expected. You might otherwise have unexpected issues when you move to testnet. We strongly recommend reviewing these differences carefully to see if you might fall into this category.

However, not everyone will need to use the local development environment. OP Mainnet is EVM equivalent (opens in a new tab), which means that OP Mainnet looks almost exactly like Ethereum under the hood. If you don't fall into one of the above categories, you can probably get away with simply relying on existing testing tools like Truffle or Hardhat. If you don't know whether or not you should be using the development environment, feel free to hop into the developer support forum (opens in a new tab). Someone nice will help you out!

Before You Begin

The Optimism monorepo includes a devnode setup you can use (opens in a new tab).

Installation

First, make sure these components are installed. Note that the command line directions were verified under Ubuntu 20.04 LTS. Other OSes or versions may use different tools.

Install the command line utilities make and jq

sudo apt install -y make jq

Install Go programming language (opens in a new tab)

sudo apt update
wget https://go.dev/dl/go1.20.linux-amd64.tar.gz
tar xvzf go1.20.linux-amd64.tar.gz
sudo cp go/bin/go /usr/bin/go
sudo mv go /usr/lib
echo export GOROOT=/usr/lib/go >> ~/.bashrc

Install Docker (the engine version is enough) (opens in a new tab)

The latest version of docker uses docker compose instead of a separate docker-compose executable. To process scripts that use docker-compose, run these commands:

echo docker compose '$*' | sudo tee /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose 

Clone the Optimism monorepo

git clone https://github.com/ethereum-optimism/optimism.git
cd optimism

Operations

  • To start, run (in the root directory of the monorepo) make devnet-up.
    The first time it runs it will be relatively slow because it needs to download the images, after that it will be faster.

  • To stop, run (in the root directory of the monorepo) make devnet-down.

  • To clean everything, run (in the root directory of the monorepo) make devnet-clean.

Additional Info

  • The monorepo includes the L1 contract addresses (opens in a new tab). The L2 contract addresses are, of course, the standard ones.

  • There are some differences between the development node and the real world (a.k.a. Ethereum mainnet and OP Mainnet):

    ParameterReal-worldDevnode
    L1 chain ID1900
    L2 chain ID10901
    Time between L1 blocks (in seconds)123
  • Test ETH:

    • Address: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
    • Private key: ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80