Compile and build the various required with the `build` command:
You can also build specific components as follows:
```shell
yarn build:contracts
yarn build
```
### Deploying the Contracts
#### Required environment variables
You must set the following environment variables to execute a deployment:
```bash
# 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=...
You must set several required environment variables before you can execute a deployment.
Duplicate the file [`.env.example`](./.env.example) and rename your duplicate to `.env`.
Fill out each of the environment variables before continuing.
# RPC URL connected to the L1 chain we're deploying to
export CONTRACTS_RPC_URL=...
#### Creating a deployment configuration
# 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 configuration file inside of the [deploy-config](./deploy-config/) folder.
Deployment configuration files are TypeScript files that export an object that conforms to the `DeployConfig` type.
See [mainnet.ts](./deploy-config/mainnet.ts) for an example deployment configuration.
We recommend duplicating an existing deployment config and modifying it to satisfy your requirements.
Before you can carry out a deployment, you must create a deployment script.
See [mainnet.sh](./scripts/deploy-scripts/mainnet.sh) for an example deployment script.
We recommend duplicating an existing deployment script and modifying it to satisfy your requirements.
#### Executing a deployment
Most variables within the deploy script are relatively self-explanatory.
If you intend to upgrade an existing system you **MUST**[include the following argument](https://github.com/ethereum-optimism/optimism/blob/6f633f915b34a46ac14430724bed9722af8bd05e/packages/contracts/scripts/deploy-scripts/mainnet.sh#L33) in the deploy script:
Once you've created your deploy config, you can execute a deployment with the following command:
```
--tags upgrade
npx hardhat deploy --network <my network name>
```
If you are deploying a system from scratch, you should **NOT** include `--tags upgrade` or you will fail to deploy several contracts.
Note that this only applies to fresh deployments.
If you want to upgrade an existing system (instead of deploying a new system from scratch), you must use the following command instead:
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.
...
...
@@ -134,19 +124,29 @@ Ownership of these addresses will be automatically returned to the original owne
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.
After your deployment is complete, your new contracts will be written to an artifacts directory in `./deployments/<my network name>`.
#### Verifying contract source code
Contracts will be automatically verified via both [Etherscan](https://etherscan.io) and [Sourcify](https://sourcify.dev/) during the deployment process.
If there was an issue with verification during the deployment, you can manually verify your contracts with the command:
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](./scripts/deploy-scripts/mainnet-genesis.sh).
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.
We guarantee this by creating a genesis file in which certain contracts are already within the L2 state at the genesis block.
To create the genesis file for your network, you must first deploy the L1 contracts using the appropriate commands from above.
Once you've deployed your contracts, run the following command:
```
npx hardhat take-dump --network <my network name>
```
Execute this script to generate the genesis file.
You will find this genesis file at `./dist/dumps/state-dump.latest.json`.
A genesis file will be created for you at `/genesis/<my network name>.json`.