Package Exports
- @eth-optimism/contracts
- @eth-optimism/contracts/dist/contract-deployed-artifacts
- @eth-optimism/contracts/dist/contract-deployed-artifacts.js
- @eth-optimism/contracts/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@eth-optimism/contracts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Optimism Smart Contracts
@eth-optimism/contracts contains the various Solidity smart contracts used within the Optimism system.
Some of these contracts are meant to be deployed to Ethereum ("Layer 1"), while others are meant to be deployed to Optimism ("Layer 2").
Within each contract file you'll find the network upon which the contract is meant to be deloyed, listed as either EVM (for Ethereum) or OVM (for Optimism).
If neither EVM nor OVM are listed, the contract is likely intended to be used on either network.
Usage (npm)
You can import @eth-optimism/contracts to use the Optimism contracts within your own codebase.
Install via npm or yarn:
npm install @eth-optimism/contractsWithin your contracts:
import { SomeContract } from "@eth-optimism/contracts/path/to/SomeContract.sol";Note that the /path/to/SomeContract.sol is the path to the target contract within the contracts folder inside of this package.
For example, the L1CrossDomainMessenger contract is located at packages/contracts/contracts/L1/messaging/L1CrossDomainMessenger.sol, relative to this README.
You would therefore import the contract as:
import { L1CrossDomainMessenger } from "@eth-optimism/contracts/L1/messaging/L1CrossDomainMessenger.sol";Guide for Developers
Setup
Install the following:
Clone the repo:
git clone https://github.com/ethereum-optimism/contracts.git
cd contractsInstall npm packages:
yarn installRunning Tests
Tests are executed via yarn:
yarn testRun specific tests by giving a path to the file you want to run:
yarn test ./test/path/to/my/test.spec.tsMeasuring test coverage:
yarn test:coverageThe output is most easily viewable by opening the html file in your browser:
open ./coverage/index.htmlCompiling and Building
Easiest way is to run the primary build script:
yarn buildRunning the full build command will perform the following actions:
build:contracts- Compile all Solidity contracts with both the EVM and OVM compilers.build:typescript- Builds the typescript files that are used to export utilities into js.build:copy- Copies various other files into the dist folder.build:dump- Generates a genesis state from the contracts that L2 geth will use.build:typechain- Generates TypeChain artifacts.
You can also build specific components as follows:
yarn build:contractsDeploying the Contracts
Required environment variables
You must set the following environment variables to execute a deployment:
# Name for the network to deploy to ("mainnet", "kovan", etc.)
export CONTRACTS_TARGET_NETWORK=...
# Private key that will send deployment transactions
export CONTRACTS_DEPLOYER_KEY=...
# RPC URL connected to the L1 chain we're deploying to
export CONTRACTS_RPC_URL=...
# Your Etherscan API key for the L1 network
export ETHERSCAN_API_KEY=...Creating a deployment script
Before you can carry out a deployment, you must create a deployment script. See mainnet.sh for an example deployment script. We recommend duplicating an existing deployment script and modifying it to satisfy your requirements.
Most variables within the deploy script are relatively self-explanatory. If you intend to upgrade an existing system you MUST include the following argument in the deploy script:
--tags upgradeIf you are deploying a system from scratch, you should NOT include --tags upgrade or you will fail to deploy several contracts.
Executing a deployment
Once you've created your deploy script, simply run the script to trigger a deployment. During the deployment process, you will be asked to transfer ownership of several contracts to a special contract address. You will also be asked to verify various configuration values. This is a safety mechanism to make sure that actions within an upgrade are performed atomically. Ownership of these addresses will be automatically returned to the original owner address once the upgrade is complete. The original owner can always recover ownership from the upgrade contract in an emergency. Please read these instructions carefully, verify each of the presented configuration values, and carefully confirm that the contract you are giving ownership to has not been compromised (e.g., check the code on Etherscan).
After your deployment is complete, your new contracts will be written to an artifacts directory in ./deployments/<name>.
Your contracts will also be automatically verified as part of the deployment script.
Creating a genesis file
Optimism expects that certain contracts (called "predeploys") be deployed to the L2 network at pre-determined addresses.
Doing this requires that you generate a special genesis file to be used by your corresponding L2Geth nodes.
You must first create a genesis generation script.
Like in the deploy script, we recommend starting from an existing script.
Modify each of the values within this script to match the values of your own deployment, taking any L1 contract addresses from the ./deployments/<name> folder that was just generated or modified.
Execute this script to generate the genesis file.
You will find this genesis file at ./dist/dumps/state-dump.latest.json.
You can then ingest this file via geth init.
Hardhat tasks
Whitelisting
Optimism has removed the whitelist from the Optimism mainnet.
However, if you are running your own network and still wish to use the whitelist, you can manage the whitelist with the whitelist task.
Run the following to get help text for the whitelist command:
npx hardhat whitelist --helpWithdrawing fees
Any wallet can trigger a withdrawal of fees within the SequencerFeeWallet contract on L2 back to L1 as long as a threshold balance has been reached.
Fees within the wallet will return to a fixed address on L1.
Run the following to get help text for the withdraw-fees command:
npx hardhat withdraw-fees --helpSecurity
Please refer to our Security Policy for information about how to disclose security issues with this code. We also maintain a bug bounty program via Immunefi with a maximum payout of $2,000,042 for critical bug reports.