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 = "1.0"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
stdreqwestalloy-core/defaultessentials
Essentials
essentials:contractprovider-httprpc-typessigner-local
Full, a set of the most commonly used flags to get started with alloy.
full:consensuseipsessentialsk256kzgnetworkprovider-wsprovider-ipcprovider-trace-apiprovider-txpool-apiprovider-debug-apiprovider-anvil-apipubsub
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
adminEthereum 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-debug - Types for the
debugEthereum JSON-RPC namespace - alloy-rpc-types-engine - Types for the
engineEthereum JSON-RPC namespace - alloy-rpc-types-eth - Types for the
ethEthereum JSON-RPC namespace - alloy-rpc-types-mev - Types for the MEV bundle JSON-RPC namespace.
- alloy-rpc-types-trace - Types for the
traceEthereum JSON-RPC namespace - alloy-rpc-types-txpool - Types for the
txpoolEthereum 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
