pub struct Anvil { /* private fields */ }
Expand description
Builder for launching anvil
.
§Panics
If spawn
is called without anvil
being available in the user’s $PATH
§Example
use alloy_node_bindings::Anvil;
let port = 8545u16;
let url = format!("http://localhost:{}", port).to_string();
let anvil = Anvil::new()
.port(port)
.mnemonic("abstract vacuum mammal awkward pudding scene penalty purchase dinner depart evoke puzzle")
.spawn();
drop(anvil); // this will kill the instance
Implementations§
source§impl Anvil
impl Anvil
sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty Anvil builder. The default port and the mnemonic are chosen randomly.
§Example
fn a() {
let anvil = Anvil::default().spawn();
println!("Anvil running at `{}`", anvil.endpoint());
sourcepub fn at(path: impl Into<PathBuf>) -> Self
pub fn at(path: impl Into<PathBuf>) -> Self
Creates an Anvil builder which will execute anvil
at the given path.
§Example
fn a() {
let anvil = Anvil::at("~/.foundry/bin/anvil").spawn();
println!("Anvil running at `{}`", anvil.endpoint());
sourcepub fn path<T: Into<PathBuf>>(self, path: T) -> Self
pub fn path<T: Into<PathBuf>>(self, path: T) -> Self
Sets the path
to the anvil
cli
By default, it’s expected that anvil
is in $PATH
, see also
std::process::Command::new()
sourcepub fn port<T: Into<u16>>(self, port: T) -> Self
pub fn port<T: Into<u16>>(self, port: T) -> Self
Sets the port which will be used when the anvil
instance is launched.
sourcepub const fn chain_id(self, chain_id: u64) -> Self
pub const fn chain_id(self, chain_id: u64) -> Self
Sets the chain_id the anvil
instance will use.
sourcepub fn mnemonic<T: Into<String>>(self, mnemonic: T) -> Self
pub fn mnemonic<T: Into<String>>(self, mnemonic: T) -> Self
Sets the mnemonic which will be used when the anvil
instance is launched.
sourcepub const fn block_time(self, block_time: u64) -> Self
pub const fn block_time(self, block_time: u64) -> Self
Sets the block-time in seconds which will be used when the anvil
instance is launched.
sourcepub const fn block_time_f64(self, block_time: f64) -> Self
pub const fn block_time_f64(self, block_time: f64) -> Self
Sets the block-time in sub-seconds which will be used when the anvil
instance is launched.
Older versions of anvil
do not support sub-second block times.
sourcepub const fn fork_block_number(self, fork_block_number: u64) -> Self
pub const fn fork_block_number(self, fork_block_number: u64) -> Self
Sets the fork-block-number
which will be used in addition to Self::fork
.
Note: if set, then this requires fork
to be set as well
sourcepub fn fork<T: Into<String>>(self, fork: T) -> Self
pub fn fork<T: Into<String>>(self, fork: T) -> Self
Sets the fork
argument to fork from another currently running Ethereum client
at a given block. Input should be the HTTP location and port of the other client,
e.g. http://localhost:8545
. You can optionally specify the block to fork from
using an @ sign: http://localhost:8545@1599200
sourcepub const fn timeout(self, timeout: u64) -> Self
pub const fn timeout(self, timeout: u64) -> Self
Sets the timeout which will be used when the anvil
instance is launched.
sourcepub fn spawn(self) -> AnvilInstance
pub fn spawn(self) -> AnvilInstance
sourcepub fn try_spawn(self) -> Result<AnvilInstance, NodeError>
pub fn try_spawn(self) -> Result<AnvilInstance, NodeError>
Consumes the builder and spawns anvil
. If spawning fails, returns an error.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Anvil
impl RefUnwindSafe for Anvil
impl Send for Anvil
impl Sync for Anvil
impl Unpin for Anvil
impl UnwindSafe for Anvil
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)