Deploying a basic contract on Remix


Optimism is the first EVM equivalent (opens new window) L2 system, which means that it's almost 100% identical to Ethereum. The process of deploying a contract to Optimism is exactly the same as deploying a contract to Ethereum. We'll demonstrate how easy it is to get started by deploying a basic contract to the Optimism Kovan testnet using Remix (opens new window).

# Requirements

Just like with Ethereum, you'll need a wallet to use to interact with Optimism. Here we'll be using the MetaMask (opens new window) Chrome extension to interact with the Optimism Kovan testnet. You can probably use other wallets and/or extensions, but this guide will include screenshots of MetaMask. We recommend using MetaMask to simplify the process of following along.

# Connecting to Optimism

MetaMask requires you to manually connect to new Ethereum-based networks before you can interact with them. You can find more information about the connection process on the Optimism Help Center (opens new window).

For now, simply head to this link (opens new window) and click "Connect". Accept the popup that shows up in MetaMask and you'll be connected to the Optimism Kovan testnet.

# Getting some testnet ETH

Like on Ethereum, transaction fees on Optimism are paid in ETH. You'll need some ETH on the Optimism Goerli testnet to deploy a contract. See how to get testnet ETH here.

# Writing a quick contract

Once you've got your testnet ETH, it's time to write a contract. Head over to Remix (opens new window) and create a new file (you can name this whatever you want). You're free to drop whatever code you want in this file (anything that runs on Ethereum will run on Optimism!) but here's some sample code that you can use:

contract MyContract {
    address public owner;

    constructor() {
        owner = msg.sender;
    }

    function setOwner(address newOwner) public {
        require(msg.sender == owner);
        owner = newOwner;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12

Save the file (ctrl+s) to automatically compile it. Now it's time to deploy!

# Deploying your contract

Deploying contracts with Remix is as easy as 1-2-3!

  1. Select the Deployment tab:
  1. Select the "Injected Web3" environment:
  1. Click "Deploy"!

Accept the popup in MetaMask and you're all done! Your contract deployment should take less than a second (Optimism is fast). If you've used Remix to deploy contracts to Ethereum before, you'll notice that the process of deploying to Optimism has been 100% identical. That's the power of EVM equivalence (opens new window)!

# Interacting with your contract

Now that your contract has been deployed you'll be able to interact with it just like you'd interact with a contract on Ethereum. You can try messing around with the contract directly in Remix by expanding the newly created contract and triggering one of the contract functions. Try querying the current owner:

# Viewing your contract on Etherscan

You might want to see more information about your contract by visiting Optimistic Etherscan (opens new window). Drop in the address of your contract and you'll get all the information that you'd get from the standard Etherscan explorer:

You can also verify the source code of your contract by going through the standard source code verification flow:

# Diving deeper

That's really all there is to deploying a contract on Optimism. It's exactly like deploying a contract on Ethereum. We hope you didn't learn anything new!

If you're itching to start building a more complex contract, check out our next section on using your favorite tools with Optimism!