## Creating a L2 Rollup testnet.
### Software Dependencies.
first ensure you have these dependencies installed on your device.

## Build the Optimism monorepo
1. Clone the Optimism Monorepo
This will clone the optimism monorepo from Github to your local machine.
`cd ~
git clone https://github.com/ethereum-optimism/optimism.git`
2. Enter the Optimism Monorepo
`cd optimism`
3. check out to the right branch
4. This command will switch you to the tutorials/chain branch.
```
git checkout tutorials/chain
```
4.Check your dependencies
```
./packages/contracts-bedrock/scripts/getting-started/versions.sh
```
This command will print these to confirm your dependecies.
Dependency | Minimum | Actual
git 2 2.34.1
go 1.21 1.21.3
node 20 23.7.0
pnpm 8 9.15.4
foundry 0.2.0 1.0.0
make 3 4.3
jq 1.6 1.6
direnv 2 2.25.2
5. Install dependencies
This will Installs all dependencies listed in the project's package.json
also Creates a node_modules folder with all required libraries (e.g., Ethereum tooling, Hardhat, TypeScript).
```
pnpm install
```
6.Build the various packages inside of the Optimism Monorepo
This compiles three critical components of the Optimism stack:
a. op-node
b.op-batcher
c. op-proposer
Also pnpm build
This builds all the TypeScript/Solidity packages in the monorepo:
```
make op-node op-batcher op-proposer
pnpm build
```
you should have this succesfully build
✔ nx run @eth-optimism/core-utils:build (4s)
✔ nx run @eth-optimism/common-ts:build (2s)
✔ nx run @eth-optimism/contracts-bedrock:build (4m)
✔ nx run @eth-optimism/contracts-ts:build (3s)
✔ nx run @eth-optimism/fee-estimation:build (4s)
✔ nx run @eth-optimism/sdk:build (9s)
✔ nx run @eth-optimism/web3.js-plugin:build (7s)
✔ nx run @eth-optimism/chain-mon:build (3s)
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target build for 8 projects (4m)
### To build Op-Geth
1. Clone op-geth
2. This will Creates a new folder called op-geth in your current directory.
Downloads all the code, history, and branches from the repository.
```
cd ~
git clone https://github.com/ethereum-optimism/op-geth.git
```
2. Enter op-geth
```
cd op-geth
```
3.Build op-geth
this is going to create geth - binary for running optimism also Processing rollup transactions differently than mainnet Ethereum.
```
make geth
```
### next:
### You need to fill out the environmental variables:
1.Enter the Optimism Monorepo
```
cd ~/optimism
```
2.Duplicate the sample environment variable file
```
cp .envrc.example .envrc
```
3. Generate new addresses
4. This will generate test wallets and you fund them with ETH for local development
```
./packages/contracts-bedrock/scripts/getting-started/wallets.sh
```
Make sure that you see output that looks something like the following:
```
Copy the following into your .envrc file:
# Admin address
export GS_ADMIN_ADDRESS=0x9625B9aF7C42b4Ab7f2C437dbc4ee749d52E19FC
export GS_ADMIN_PRIVATE_KEY=0xbb93a75f64c57c6f464fd259ea37c2d4694110df57b2e293db8226a502b30a34
# Batcher address
export GS_BATCHER_ADDRESS=0xa1AEF4C07AB21E39c37F05466b872094edcf9cB1
export GS_BATCHER_PRIVATE_KEY=0xe4d9cd91a3e53853b7ea0dad275efdb5173666720b1100866fb2d89757ca9c5a
# Proposer address
export GS_PROPOSER_ADDRESS=0x40E805e252D0Ee3D587b68736544dEfB419F351b
export GS_PROPOSER_PRIVATE_KEY=0x2d1f265683ebe37d960c67df03a378f79a7859038c6d634a61e40776d561f8a2
# Sequencer address
export GS_SEQUENCER_ADDRESS=0xC06566E8Ec6cF81B4B26376880dB620d83d50Dfb
export GS_SEQUENCER_PRIVATE_KEY=0x2a0290473f3838dbd083a5e17783e3cc33c905539c0121f9c76614dda8a38dca
```
4. Save the addresses
Copy the output from the previous step and paste it into your .envrc file as directed.
Ensure that you fund the addresses with the following amounts when using Sepolia:
Admin — 0.5 Sepolia ETH
Batcher — 0.1 Sepolia ETH
Proposer — 0.2 Sepolia ETH
### Load environment variables
```
direnv allow
```
### Confirm that the variables were loaded
If you don't see this output,
Make sure you've configured direnv properly and run direnv allow again so that you see the desired output
```
direnv: loading ~/optimism/.envrc
direnv: export +DEPLOYMENT_CONTEXT +ETHERSCAN_API_KEY +GS_ADMIN_ADDRESS +GS_ADMIN_PRIVATE_KEY +GS_BATCHER_ADDRESS +GS_BATCHER_PRIVATE_KEY +GS_PROPOSER_ADDRESS +GS_PROPOSER_PRIVATE_KEY +GS_SEQUENCER_ADDRESS +GS_SEQUENCER_PRIVATE_KEY +IMPL_SALT +L1_RPC_KIND +L1_RPC_URL +PRIVATE_KEY +TENDERLY_PROJECT +TENDERLY_USERNAME
```
ERROR's
optimism$ cp .envrc.example .envrc
cp: cannot stat '.envrc.example': No such file or directory
when you get this errors use this below:
```
$eval "(direnv hook bash)"
```
### Next is to Configure your network
### Move into the contracts-bedrock package
```
cd packages/contracts-bedrock
```
### Install Foundry dependencies
```
forge install
```
### Generate the configuration file
generate the getting-started.json configuration file inside of the deploy-config directory.
```
./scripts/getting-started/config.sh
```
### Deploy the L1 contracts
Once you've configured your network,
deploy the L1 contracts necessary for the functionality of the chain.
## Next op-deployer
The op-deployer tool simplifies the creation of genesis and rollup configuration files (genesis.json and rollup.json). These files are crucial for initializing the execution client (op-geth) and consensus client (op-node) for your network.
1. use this command first:
```
forge script scripts/deploy/Deploy.s.sol:Deploy --private-key $GS_ADMIN_PRIVATE_KEY --broadcast --rpc-url $L1_RPC_URL --slow
```
Replace <YOUR_L1_CHAIN_ID> and <YOUR_L2_CHAIN_ID> with their respective values from your .envr file.
1. Deploy the L1 contracts
To deploy your chain to L1, run:
```
./bin/op-deployer apply --workdir .deployer \
--l1-rpc-url <RPC_URL_FOR_L1> \
--private-key <DEPLOYER_PRIVATE_KEY_HEX>
```
Replace <RPC_URL_FOR_L1> with the L1 RPC URL.
Replace <DEPLOYER_PRIVATE_KEY_HEX> with the private key of the account used for deployment.
2.Generate your L2 genesis file and rollup file
After your L1 contracts have been deployed, generate the L2 genesis and rollup configuration files by inspecting the deployer's state.json.
```
./bin/op-deployer inspect genesis --workdir .deployer <L2_CHAIN_ID> > .deployer/genesis.json
./bin/op-deployer inspect rollup --workdir .deployer <L2_CHAIN_ID> > .deployer/rollup.json
```
## Initialize op-geth
1. Navigate to the op-geth directory
```
cd ~/op-geth
```
2.Create a data directory folder
```
mkdir datadir
```
3.Build the op-geth binary
```
make geth
```
4. Initialize op-geth
```
build/bin/geth init --state.scheme=hash --datadir=datadir genesis.json
```