pub struct Anvil { /* private fields */ }Expand description
Builder for launching anvil.
Anvil::spawn panics on any startup failure; use Anvil::try_spawn to handle errors.
§Example
use alloy_node_bindings::Anvil;
let anvil = Anvil::new()
.mnemonic("abstract vacuum mammal awkward pudding scene penalty purchase dinner depart evoke puzzle")
.try_spawn()?;
println!("Anvil is listening at {}", anvil.endpoint());
drop(anvil); // this will kill the instanceImplementations§
Source§impl Anvil
impl Anvil
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an Anvil builder.
Unless configured, port zero is passed so the OS chooses an available port, while account and mnemonic defaults are left to Anvil.
§Example
fn a() {
let anvil = Anvil::default().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 host<T: Into<String>>(self, host: T) -> Self
pub fn host<T: Into<String>>(self, host: T) -> Self
Sets the host which will be used when the anvil instance is launched.
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.
Port zero asks the OS to choose an available port. Read AnvilInstance::port or
AnvilInstance::endpoint after spawning to obtain the selected value.
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.
If not set, the instance defaults to chain id 31337.
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 fn hardfork(self, hardfork: EthereumHardfork) -> Self
pub fn hardfork(self, hardfork: EthereumHardfork) -> Self
Select the EthereumHardfork to start anvil with.
Sourcepub fn paris(self) -> Self
pub fn paris(self) -> Self
Set the EthereumHardfork to EthereumHardfork::Paris.
Sourcepub fn cancun(self) -> Self
pub fn cancun(self) -> Self
Set the EthereumHardfork to EthereumHardfork::Cancun.
Sourcepub fn shanghai(self) -> Self
pub fn shanghai(self) -> Self
Set the EthereumHardfork to EthereumHardfork::Shanghai.
Sourcepub fn prague(self) -> Self
pub fn prague(self) -> Self
Set the EthereumHardfork to EthereumHardfork::Prague.
Sourcepub fn auto_impersonate(self) -> Self
pub fn auto_impersonate(self) -> Self
Instantiate anvil with the --auto-impersonate flag.
Sourcepub fn extend_args<I, S>(&mut self, args: I)
pub fn extend_args<I, S>(&mut self, args: I)
Adds multiple arguments to pass to the anvil.
Sourcepub fn env<K, V>(self, key: K, value: V) -> Self
pub fn env<K, V>(self, key: K, value: V) -> Self
Adds an environment variable to pass to the anvil.
Sourcepub fn envs<I, K, V>(self, envs: I) -> Self
pub fn envs<I, K, V>(self, envs: I) -> Self
Adds multiple environment variables to pass to the anvil.
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.
Units: milliseconds.
Sourcepub const fn keep_stdout(self) -> Self
pub const fn keep_stdout(self) -> Self
Keep the handle to anvil’s stdout in order to read from it.
Caution: if the stdout handle isn’t used, this can end up blocking.
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, spawns anvil, and waits for it to report its listening address.
Returns an error if the process cannot be started or does not become ready before the
configured Self::timeout is observed. The deadline is checked between complete stdout
lines; a live process that emits no newline can block this call past the deadline.
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 UnsafeUnpin 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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 240 bytes