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.6", 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 - Meta-crate for the entire project, including
alloy-core
- alloy-consensus - Ethereum consensus interface
- alloy-contract - Interact with on-chain contracts
- alloy-eips - Ethereum Improvement Proposal (EIP) implementations
- alloy-genesis - Ethereum genesis file definitions
- alloy-json-rpc - Core data types for JSON-RPC 2.0 clients
- alloy-network - Network abstraction for RPC types
- alloy-network-primitives - Primitive types for the network abstraction
- alloy-node-bindings - Ethereum execution-layer client bindings
- alloy-provider - Interface with an Ethereum blockchain
- alloy-pubsub - Ethereum JSON-RPC publish-subscribe tower service and type definitions
- alloy-rpc-client - Low-level Ethereum JSON-RPC client implementation
- alloy-rpc-types - Meta-crate for all Ethereum JSON-RPC types
- alloy-rpc-types-admin - Types for the
admin
Ethereum JSON-RPC namespace - alloy-rpc-types-anvil - Types for the Anvil development node’s Ethereum JSON-RPC namespace
- alloy-rpc-types-beacon - Types for the Ethereum Beacon Node API
- alloy-rpc-types-engine - Types for the
engine
Ethereum JSON-RPC namespace - alloy-rpc-types-eth - Types for the
eth
Ethereum JSON-RPC namespace - alloy-rpc-types-mev - Types for the MEV bundle JSON-RPC namespace.
- alloy-rpc-types-trace - Types for the
trace
Ethereum JSON-RPC namespace - alloy-rpc-types-txpool - Types for the
txpool
Ethereum JSON-RPC namespace
- alloy-rpc-types-admin - Types for the
- alloy-serde - Serde-related utilities
- alloy-signer - Ethereum signer abstraction
- alloy-signer-aws - AWS KMS signer implementation
- alloy-signer-gcp - GCP KMS signer implementation
- alloy-signer-ledger - Ledger signer implementation
- alloy-signer-local - Local (private key, keystore, mnemonic, YubiHSM) signer implementations
- alloy-signer-trezor - Trezor signer implementation
- alloy-transport - Low-level Ethereum JSON-RPC transport abstraction
- alloy-transport-http - HTTP transport implementation
- alloy-transport-ipc - IPC transport implementation
- alloy-transport-ws - WS transport implementation
alloy-core
consists out of the following crates:
- alloy-core - Meta-crate for the entire project
- alloy-dyn-abi - Run-time ABI and EIP-712 implementations
- alloy-json-abi - Full Ethereum JSON-ABI implementation
- alloy-primitives - Primitive integer and byte types
- alloy-sol-macro-expander - Expander used in the Solidity to Rust procedural macro
- alloy-sol-macro-input - Input types for
sol!
-like macros - alloy-sol-macro - The
sol!
procedural macro - alloy-sol-type-parser - A simple parser for Solidity type strings
- alloy-sol-types - Compile-time ABI and EIP-712 implementations
- syn-solidity -
syn
-powered Solidity parser