Skip to content

Why Alloy?

Alloy is the next-generation Rust toolkit for Ethereum development and a complete rewrite of ethers-rs. Alloy offers a modular, high-performance, and developer-friendly experience for building on EVM-compatible chains. It addresses the various pain points of existing tooling in the Rust Ethereum ecosystem, such as perfomance bottlenecks, cumbersome APIs and having to deal with feature flag that bloat your application.


It provides a complete toolkit for Ethereum development in Rust:

  • Seamless smart contract interactions: The sol! macro enables you to parse Solidity syntax directly in Rust code, simplifying contract interactions.

  • Simplified RPC Provider Usage: Alloy enables you to connect to an EVM node in a simple and intuitive way.

  • Multi-Chain Support: The Network trait allows seamless integration with any EVM-compatible chain without feature flags.

  • Layered Architecture: Replaces monolithic middleware with composable layers and fillers, enhancing modularity and clarity.

  • Optimized Primitives: Alloy's rewritten core components deliver major performance gains across key Ethereum operations such as ABI encoding/decoding, U256 operations, and RLP encoding and decoding.

Benchmarks

Alloy's performance improvements are demonstrated through several key benchmarks.

  1. ABI Encoding: Measures the speed of encoding Solidity contract data (both static and dynamic types) into the Ethereum ABI format, which is required for making contract calls and sending transactions. For the purpose of this benchmark, we are encoding the Uniswap V2 swap function.


    // Benchmarks encode the calldata for this method
    function swap(uint amount0Out, uint amount1Out, address to, bytes
    calldata data) external;

    EthersAlloySpeedup
    Static1.12 μs90.89 ns🚀 12.32x
    Dynamic2.20 μs1.88 μs1.17x
  2. U256 Operations: Uniswap V2 Swap Calculations: U256 Math is fairly common in EVM land, specially when interacting with DeFi protocols. For this benchmark we shall calculate the token amountIn and amountOut necessary for swapping.


    EthersAlloySpeedup
    amountIn512.47 ns216.32 ns🚀 2.37x
    amountOut53.82 ns18.19 ns🚀 2.96x
  3. RLP Encoding/Decoding: Measures the speed of encoding and decoding data using Recursive Length Prefix (RLP), a serialization method used throughout Ethereum (e.g., for blocks and transactions). For this benchmark, we shall RLP encode and decode a simple struct.

    // Derive the necessary traits
    #[derive(alloy_rlp::RlpEncodable, alloy_rlp::RlpDecodable)]
    #[derive(rlp_derive::RlpDecodable, rlp_derive::RlpEncodable)]
    pub struct MyStruct {
      a: u128,
      b: Vec<u8>,
    }

    Parity-RlpAlloy-RlpSpeedup
    Encoding86.70 ns26.88 ns🚀 3.23x
    Decoding88.79 ns21.43 ns🚀 4.14x

Complete benchmarks and their source code can be found here.

Alloy is already powering major projects like Foundry, Reth, Arbitrum Stylus, OP Kona and many more. It's designed to be the performant and stable foundation for the Rust Ethereum ecosystem.