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.
How OP Deployer Runs a Script
Each deploy script has arunWithBytes(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
prepareandcontinue, forge simulates the deployment on an ephemeral anvil fork of the L1, as the deployer, without its key.continuethen checks the simulated transactions and the resulting contracts before it sends the same transactions to the L1.