This library provides a simple API for interacting with an embedded Ethereum Virtual Machine (EVM).
[]
= "0.2.4"
Supports
- Both an in-memory database and the ability to fork state from a remote node
- Snapshot of EVM state for later use
- Both raw encoding/decoding of function calls as well as alloy SolTypes
- Lightweight creation of ABI from human-readable syntax
Examples
Create and interact with the EVM
use ;
use ;
// Generate some random addresses
let addresses = generate_random_addresses;
let bob = addresses;
let alice = addresses;
// create the EVM with in-memory database (default)
let mut evm = default;
// create 2 accounts. Bob w/ 2 ether, alice w/ none
evm.create_account.unwrap;
evm.create_account.unwrap;
// check the balances
assert!;
assert!;
Fork a remote contract
Interacting with a remote contract pulls the state of the remote contract into the local in-memory database for use.
use
See uniswap for an example of using a fork and snapshot to trade a pair on Uniswap. The example includes a snapshot that it loads state from to execute Uniswap trades.
To run the example:
> cargo
Standing on the shoulders of giants...
Thanks to the following projects for making this work possible!
- revm
- alloy-rs
- foundry-rs for much of the design influence