Installation
Alloy consists of a number of crates that provide a range of functionality essential for interfacing with any Ethereum-based blockchain.
The easiest way to get started is to add the alloy crate from the command-line using Cargo:
cargo add alloyAlternatively, you can add the following to your Cargo.toml file:
alloy = "2.5.0"For a more fine-grained dependency, use the alloy crate with task-specific features or depend on
the individual crate that owns the API. See how Alloy fits together
and the feature flag reference before disabling defaults.
After alloy is added as a dependency you can now import alloy as follows:
use alloy::{
network::EthereumWallet,
node_bindings::Anvil,
primitives::U256,
providers::ProviderBuilder,
signers::local::PrivateKeySigner,
sol,
};The node_bindings module, together with the ProviderBuilder::connect_anvil* helpers, is only
available with the node-bindings feature, which the default feature set does not enable. Add it
when you want to start Anvil, Geth, or Reth from Rust, for example to run the
getting started examples:
cargo add alloy --features node-bindings