Using your favorite tools


How do you use your favorite tools for building contracts when you're working with Optimism? Just use them!

Optimism isn't just EVM compatible, it's EVM equivalent. All the Ethereum tooling you know and love should work on Optimism without lots of fiddling. Hardhat? Brownie? Truffle? Yep, yep, and yep. If you find a tool that doesn't seem to work with Optimism out of the box, try opening an issue over on GitHub (opens new window). Someone working on Optimism will probably help fix the issue pretty quickly.

# Hardhat

Configuring Hardhat to deploy your contracts to Optimism is a breeze. Simply add the following to your Hardhat config file:

module.exports = {
  networks: {
    ...
    // for mainnet
    'optimism': {
      url: "https://mainnet.optimism.io",
      accounts: [privateKey1, privateKey2, ...]
    },
    // for testnet
    'optimism-goerli': {
      url: "https://goerli.optimism.io",
      accounts: [privateKey1, privateKey2, ...]
    },
    // for the local dev environment
    'optimism-local': {
      url: "http://localhost:8545",
      accounts: [privateKey1, privateKey2, ...]
    },
  },
  ...
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# Foundry

Foundry (opens new window) is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust. Foundry supports Optimism out of the box! Just provide an Optimism RPC:

forge create ... --rpc-url=https://goerli.optimism.io/
1

Additionally, you can use forge-optimism (opens new window) to simulate the optimism context and simplify testing.

# Truffle

Configuring Truffle is easy too:

const HDWalletProvider = require('@truffle/hdwallet-provider')

...
module.exports = {
  networks: {
    ...
    // for mainnet
    'optimism': {
      provider: () => {
        return new HDWalletProvider(YOUR_MAINNET_MNEMONIC_GOES_HERE, 'https://mainnet.optimism.io')
      }
      network_id: "10"
    },
    // for testnet
    'optimism-goerli': {
      provider: () => {
        return new HDWalletProvider(YOUR_GOERLI_MNEMONIC_GOES_HERE, 'https://goerli.optimism.io')
      }
      network_id: "420"
    },
    // for the local dev environment
    'optimism-local': {
      provider: () => {
        return new HDWalletProvider('test test test test test test test test test test test junk', 'http://localhost:8545')
      }
      network_id: "420"
    }
  },
  ...
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# Brownie

We're working on getting Optimism added to the built-in list of networks (opens new window) within Brownie. For now you can add networks to Brownie manually with the following commands.

Mainnet:

brownie networks add Optimism optimism-main host=https://mainnet.optimism.io chainid=10 explorer=https://api-optimistic.etherscan.io/api multicall2=0x2DC0E2aa608532Da689e89e237dF582B783E552C
1

Testnet:

brownie networks add Optimism optimism-test host=https://goerli.optimism.io chainid=420 multicall2=0x2DC0E2aa608532Da689e89e237dF582B783E552C
1

Local:

brownie networks add Optimism optimism-local host=https://mainnet.optimism.io chainid=420
1

# Waffle

Starting from Waffle (opens new window) v4.x.x you can use Waffle chai matchers to test your smart contracts on Optimism. We recommend following this guide (opens new window)(scroll down to Waffle section) to get to know Waffle (opens new window).

If you want to add Waffle (opens new window) to an already existing project, you can install it with (replace npm install with the package manager's you're using relevant command):

npm install --save-dev [email protected] @ethereum-waffle/[email protected]
1

# Other tools

Got a favorite tool that works well with Optimism? Want it displayed on this page? Make a pull request over on the docs repository (opens new window)!