Available on crate feature dev-rpc only.
Expand description

A middleware supporting development-specific JSON RPC methods

§Example

use ethers_providers::{Provider, Http, Middleware, DevRpcMiddleware};
use ethers_core::types::TransactionRequest;
use ethers_core::utils::Anvil;

let anvil = Anvil::new().spawn();
let provider = Provider::<Http>::try_from(anvil.endpoint())?;
let client = DevRpcMiddleware::new(provider);

// snapshot the initial state
let block0 = client.get_block_number().await?;
let snap_id = client.snapshot().await?;

// send a transaction
let accounts = client.get_accounts().await?;
let from = accounts[0];
let to = accounts[1];
let balance_before = client.get_balance(to, None).await?;
let tx = TransactionRequest::new().to(to).value(1000).from(from);
client.send_transaction(tx, None).await?.await?;
let balance_after = client.get_balance(to, None).await?;
assert_eq!(balance_after, balance_before + 1000);

// revert to snapshot
client.revert_to_snapshot(snap_id).await?;
let balance_after_revert = client.get_balance(to, None).await?;
assert_eq!(balance_after_revert, balance_before);

Structs§

Enums§