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 with the full feature flag from the command-line using Cargo:

cargo add alloy --features full

Alternatively, you can add the following to your Cargo.toml file:

alloy = { version = "0.3", features = ["full"] }

For a more fine-grained control over the features you wish to include, you can add the individual crates to your Cargo.toml file, or use the alloy crate with the features you need.

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,
};

Features

The alloy meta-crate defines a number of feature flags:

Default

  • std
  • reqwest

Full, a set of the most commonly used flags to get started with alloy.

  • full

General

  • consensus
  • contract
  • eips
  • genesis
  • network
  • node-bindings

Providers

  • providers
  • provider-http
  • provider-ipc
  • provider-ws

RPC

  • rpc
  • json-rpc
  • rpc-client
  • rpc-client-ipc
  • rpc-client-ws
  • rpc-types
  • rpc-types-admin
  • rpc-types-anvil
  • rpc-types-beacon
  • rpc-types-debug
  • rpc-types-engine
  • rpc-types-eth
  • rpc-types-json
  • rpc-types-mev
  • rpc-types-trace
  • rpc-types-txpool

Signers

  • signers
  • signer-aws
  • signer-gcp
  • signer-ledger
  • signer-ledger-browser
  • signer-ledger-node
  • signer-local
  • signer-trezor
  • signer-keystore
  • signer-mnemonic
  • signer-mnemonic-all-languages
  • signer-yubihsm

By default alloy uses reqwest as HTTP client. Alternatively one can switch to hyper. The reqwest and hyper feature flags are mutually exclusive.

A complete list of available features can be found on docs.rs or in the alloy crate’s Cargo.toml.

The feature flags largely correspond with and enable features from the following individual crates.

Crates

alloy consists out of the following crates:

alloy-core consists out of the following crates: