You can also build specific components as follows:
```shell
```shell
yarn build:contracts
yarn build
```
```
### Deploying the Contracts
### Deploying the Contracts
#### Required environment variables
#### Required environment variables
You must set the following environment variables to execute a deployment:
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`.
```bash
Fill out each of the environment variables before continuing.
# 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
#### Creating a deployment configuration
export CONTRACTS_RPC_URL=...
# Your Etherscan API key for the L1 network
Before you can carry out a deployment, you must create a deployment configuration file inside of the [deploy-config](./deploy-config/) folder.
export ETHERSCAN_API_KEY=...
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.
#### Creating a deployment script
Before you can carry out a deployment, you must create a deployment script.
#### Executing a deployment
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.
Most variables within the deploy script are relatively self-explanatory.
Once you've created your deploy config, you can execute a deployment with the following command:
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:
```
```
--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.
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.
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.
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
...
@@ -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.
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).
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>`.
After your deployment is complete, your new contracts will be written to an artifacts directory in `./deployments/<my network name>`.
Your contracts will also be automatically verified as part of the deployment script.
#### 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.
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.
We guarantee this by creating a genesis file in which certain contracts are already within the L2 state at the genesis block.
You must first create a genesis generation script.
To create the genesis file for your network, you must first deploy the L1 contracts using the appropriate commands from above.
Like in the deploy script, we recommend starting from an [existing script](./scripts/deploy-scripts/mainnet-genesis.sh).
Once you've deployed your contracts, run the following command:
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.
```
npx hardhat take-dump --network <my network name>
```
Execute this script to generate the genesis file.
A genesis file will be created for you at `/genesis/<my network name>.json`.
You will find this genesis file at `./dist/dumps/state-dump.latest.json`.