sim:fork
Fork the blockchain and execute commands in a simulation.
Smart blocks: cannot be nested. This command performs an immediate wallet, RPC, external-service or control-flow operation and cannot run inside an atomic batch.
Syntax
Section titled “Syntax”sim:fork <block>Arguments
Section titled “Arguments”| Name | Type | Evaluation | Description |
|---|---|---|---|
block | block | Build time | Commands to execute in the fork |
Options
Section titled “Options”| Name | Type | Evaluation | Description |
|---|---|---|---|
--block-number | number | Build time | Block number to fork from |
--as | address | Build time | Account the block is run by: @me inside the fork, impersonated for every transaction that names no other sender. Defaults to the connected account. |
--on | chain | Build time | Chain to fork (name or id), and the chain --block-number is a block of. Defaults to the current chain. |
--from | address | Build time | Deprecated: use --as. |
--auth-token | string | Build time | RPC provider authentication token |
--using | simulation-mode | Build time | Simulation backend (anvil, hardhat, tenderly, tenderly-multichain, ethereumjs, revm, rpc: the chain's own node, through eth_simulateV1) |
Examples
Section titled “Examples”# Fork and set account balancesim:fork --using anvil ( sim:set-balance @me 100e18)
# Run the block as another accountsim:fork --as 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 ( sim:set-balance @me 100e18)Account and chain
Section titled “Account and chain”--as names the account the block is run by, and --on the chain the
fork is of. They are the options of switch,
which works the same way inside a fork:
load sim
set $who 0x44fA8E6f47987339850636F88629646662444217
sim:fork --as $who --on gnosis ( sim:set-balance @me 100e18 exec 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d "deposit()" --value 1e18)- Inside
--as,@meis that account and every transaction that names no other sender is sent from it (impersonated).--fromdid the same and is deprecated. --onforks the named chain whatever chain the script is on, and--block-numberis a block of that chain. Without it the fork is of the current chain.- When the block ends, the script is back on the chain and the account it had before the fork.
- A
switchwithout a block inside the fork holds until the end of the block it is written in: the fork itself, or aniforloopinside it. - The fork's block is a block like any other: when it ends, the fork is back on the chain it started on (nothing happens if it never left it).
- Supported backends:
anvil,hardhat,tenderly,tenderly-multichain,ethereumjs,revm(default),rpc - The
ethereumjsandrevmbackends run entirely in the browser — no external node needed revmexecutes on the Rust EVM compiled to WebAssembly: much faster opcode execution thanethereumjson compute-heavy simulations, with identical semantics (state still streams lazily from the upstream RPC)rpchas the chain's own node run the simulation througheth_simulateV1, on top of the pinned block: nothing is fetched or executed in the browser, and the chain's own client decides every opcode (an L2's system contracts and precompiles included). The node keeps no session, so each transaction and each read sends the run so far again;sim:set-*become state overrides andwaita later block. It needs an RPC that offerseth_simulateV1(Geth, Nethermind and Reth implement it; providers differ), and one that keeps the pinned block's state (an archive node for an old--block-number). A run is limited to the node's maximum number of simulated blocks: eachwait,mine, and eachsim:set-*after a transaction opens one- All commands inside the fork block execute against the simulated state
- Changes do not affect the real chain
batch (...)inside a fork simulates an EIP-7702 batch: if the sender EOA has no delegation yet, the fork installs a delegation to MetaMask's EIP7702StatelessDeleGator (0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B) and executes all batched calls atomically in a single self-call transaction. An existing delegation on the EOA is reused as-is.
Cross-chain simulation
Section titled “Cross-chain simulation”A fork is multichain: switch inside a fork block moves between one fork per chain instead of failing, and each chain keeps its own state, so switching back and forth is safe.
load simload bridges
sim:fork --using anvil ( bridges:bridge 100e6 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 to base --using CCTPv2 switch base set $balance @get(0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 "balanceOf(address)(uint256)" @me) sim:expect @bool($balance > 0))Bridge transfers are auto-relayed. When a bridge transaction executes, the fork scans its receipt for the source event; switching to the destination chain then executes the destination leg there — a mocked Circle attestation driving the real receiveMessage mint for CCTP, an impersonated relayer fill for Across, an impersonated endpoint calling lzReceive for LayerZero, a replayed deposit for the canonical bridges. bridges:claim is therefore unnecessary inside a fork. When the block ends on another chain than the one the fork started on, the fork returns to its starting chain, as any block puts its chain back, and transfers bound for it are delivered then. Transfers whose destination chain the fork is never on are reported when the block ends.
Each backend hosts the extra chains differently:
| Backend | How it goes multichain |
|---|---|
ethereumjs | One in-memory fork per chain, created on the first switch |
revm (default) | Same as ethereumjs: one in-memory (WASM) fork per chain |
rpc | One run per chain, each simulated by that chain's own node |
tenderly | One Virtual TestNet per chain |
tenderly-multichain | A single multichain Virtual Environment holding every chain the script switches to (one dashboard, one teardown). Its networks are attached when the environment is created, so switch targets must be literal |
anvil / hardhat | The single local node is re-forked on each switch, saving and restoring each chain's state (needs dumpState/loadState, which Anvil supports) |
Limitations: secondary chains fork at their latest block (--block-number pins only the starting chain), each fork keeps its own clock (wait advances the active one), and a delivered destination leg is not itself relayed onward.
See Also
Section titled “See Also”- set-balance — set account ETH balances
- expect — assert conditions
- wait — advance time