Skip to content

Simulation

The sim module lets you test scripts on a forked chain without spending gas or affecting real state.

load sim
sim:fork (
# Everything inside runs on a simulated fork
sim:set-balance @me 100e18
exec @token(DAI) "transfer(address,uint256)" 0x1234... @token.amount(DAI 50)
)

EVMcrispr supports multiple simulation backends:

BackendFlagNotes
EthereumJS(default)Runs in-browser, no external node needed
Anvil--using anvilFastest, needs anvil running locally
Hardhat--using hardhatNeeds Hardhat node running locally
Tenderly--using tenderlyCloud-based, needs --auth-token
# Use Anvil
sim:fork --using anvil (
sim:set-balance @me 100e18
)
# Use Tenderly
sim:fork --using tenderly --auth-token "your-token" (
sim:set-balance @me 100e18
)
sim:fork --block-number 18000000 (
print @get(@token(DAI) "totalSupply()(uint256)")
)

Use --from to simulate as a specific address:

sim:fork --from 0xWhale... (
exec @token(DAI) "transfer(address,uint256)" @me @token.amount(DAI 1000)
)
sim:set-balance @me 100e18
sim:set-balance 0x1234... 50e18
sim:set-code 0xContract... 0x6080...
sim:set-storage-at 0xContract... 0x00 0x01

Use expect to verify conditions during simulation:

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.

Use wait to move forward in time (useful for timelocks, vesting, etc.):

sim:fork (
# Advance 1 day (86400 seconds)
sim:wait 86400
# Advance with a specific block period (seconds per block)
sim:wait 86400 12
)
load aragonos
load sim
sim:fork (
aragonos:connect my-dao.aragonid.eth (
# Test a governance action
grant @me @app(voting) CREATE_VOTES_ROLE
install $agent agent:new
)
)