Skip to main content
OP Deployer does its on-chain work with Solidity scripts, which it runs with forge. The scripts live in the contracts bundle that OP Deployer uses (see Artifacts Locators). A script signals each transaction to send with vm.broadcast.

Why Use Solidity Scripts?

Solidity scripts are much more ergonomic than Go code for complex on-chain interactions. They allow for:
  • Easy integration with existing Solidity-based tooling and libraries.
  • Simple ABI encoding/decoding.
  • Clear separation of concerns between inter-contract calls, and the underlying RPC calls that drive them.
The alternative is to encode all on-chain interactions in Go code. This is possible, but it is much more verbose and requires writing bindings between Go and the Solidity ABI. These bindings are error-prone and difficult to maintain.

How OP Deployer Runs a Script

Each deploy script has a runWithBytes(bytes) entrypoint. Its input is the ABI encoding of the script’s Input struct, and it returns the ABI encoding of its Output struct. OP Deployer defines both structs as Go structs with the same fields in the same order, encodes the input, runs forge script --sig 'runWithBytes(bytes)', and decodes the return value that forge prints. OP Deployer runs forge in three ways:
  • On a live L1, forge runs the script on a fork of the L1 head, as the deployer, without its key, and records the transactions of the script. OP Deployer checks them, signs them with the deployer key and sends them itself. It sends one transaction at a time, and waits for its receipt before it sends the next.
  • For a genesis deployment, forge runs offline, on the L1 state of the deployment. Each script run loads the state that the previous run left (vm.loadAllocs) and dumps the state that it leaves (vm.dumpState). OP Deployer writes the final state into the L1 genesis.
  • For prepare and continue, forge simulates the deployment on an ephemeral anvil fork of the L1, as the deployer, without its key. continue then checks the simulated transactions and the resulting contracts before it sends the same transactions to the L1.
OP Deployer never compiles the contracts. It runs forge against the compiled bundle, and stops with an error if forge starts to compile, because a compile could change the deployed bytecode. So the runs need no solc compiler. Each forge run uses its own copy of the compile cache and its own broadcast directory, so that concurrent runs on one bundle do not interfere.