Simulation
The sim module lets you test scripts on a forked chain without spending
gas or affecting real state.
Basic Usage
Section titled “Basic Usage”load sim
sim:fork ( # Everything inside runs on a simulated fork sim:set-balance @me 100e18 exec @token(DAI) "transfer(address,uint256)" 0x4F2083f5fBede34C2714aFfb3105539775f7FE64 @token.amount(DAI 50))Choosing a Backend
Section titled “Choosing a Backend”EVMcrispr supports multiple simulation backends:
| Backend | Flag | Notes |
|---|---|---|
| EthereumJS | (default) | Runs in-browser, no external node needed |
| Anvil | --using anvil |
Fastest, needs anvil running locally |
| Hardhat | --using hardhat |
Needs Hardhat node running locally |
| Tenderly | --using tenderly |
Cloud-based, needs --auth-token |
load sim
# Use Anvilsim:fork --using anvil ( sim:set-balance @me 100e18)
# Use Tenderlysim:fork --using tenderly --auth-token "your-token" ( sim:set-balance @me 100e18)Forking at a Specific Block
Section titled “Forking at a Specific Block”load sim
sim:fork --block-number 18000000 ( print @get(@token(DAI) "totalSupply()(uint256)"))Impersonating Accounts
Section titled “Impersonating Accounts”Use --from to simulate as a specific address:
load sim
# A well-stocked account whose balance we borrow for the simulationset $whale 0x40ec5B33f54e0E8A33A975908C5BA1c14e5BbbDf
sim:fork --from $whale ( exec @token(DAI) "transfer(address,uint256)" @me @token.amount(DAI 1000))Manipulating State
Section titled “Manipulating State”Set ETH Balance
Section titled “Set ETH Balance”load sim
sim:fork ( sim:set-balance @me 100e18 sim:set-balance 0x4F2083f5fBede34C2714aFfb3105539775f7FE64 50e18)Set Contract Bytecode
Section titled “Set Contract Bytecode”load sim
sim:fork ( sim:set-code 0x44fA8E6f47987339850636F88629646662444217 0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe)Set Storage Slots
Section titled “Set Storage Slots”load sim
sim:fork ( sim:set-storage-at 0x44fA8E6f47987339850636F88629646662444217 0x00 0x01)Assertions
Section titled “Assertions”Use expect to verify conditions during simulation:
load sim
sim:fork ( sim:set-balance @me 100e18
# Assert balance was set sim:expect @bool(@get(@token(DAI) "balanceOf(address)(uint256)" @me) >= 0)
# Assert equality set $a 42 sim:expect @bool($a == 42)
# Assert inequality sim:expect @bool(1 != 2))If an assertion fails, the script halts with an error.
Advancing Time
Section titled “Advancing Time”Use the standard wait command to move forward in time (useful for
timelocks, vesting, etc.). Inside a fork the wait is instant — the chain’s
clock is warped instead of sleeping:
load sim
sim:fork ( # Advance 1 day (86400 seconds) wait 86400)Combining with DAO Operations
Section titled “Combining with DAO Operations”load aragonosload sim
sim:fork ( aragonos:connect my-dao.aragonid.eth ( # Test a governance action grant @me @app(voting) CREATE_VOTES_ROLE install $agent agent:new-app ))