10 unstable releases (3 breaking)

0.12.4 Mar 11, 2025
0.12.0 Mar 11, 2025
0.11.1 Feb 21, 2025
0.9.2 Jan 9, 2025
0.1.2 Sep 20, 2024

#19 in #sol

Download history 129/week @ 2025-01-04 47/week @ 2025-01-11 7/week @ 2025-01-18 6/week @ 2025-01-25 118/week @ 2025-02-01 202/week @ 2025-02-08 178/week @ 2025-02-15 180/week @ 2025-02-22 127/week @ 2025-03-01 280/week @ 2025-03-08 81/week @ 2025-03-15 13/week @ 2025-03-22 33/week @ 2025-03-29 79/week @ 2025-04-05 39/week @ 2025-04-12

168 downloads per month

MIT license

45KB
722 lines

Alloy Multicall

Easily send multicall transactions using Alloy.

Installation

Add alloy-multicall to your Cargo.toml.

alloy-multicall = "0.12.4"

Example

use alloy::{
    dyn_abi::DynSolValue,
    primitives::{address, U256},
    sol,
    sol_types::JsonAbiExt as _,
};
use alloy_multicall::Multicall;

sol! {
    #[derive(Debug)]
    #[sol(abi)]
    function getAmountsOut(uint amountIn, address[] memory path)
        public
        view
        virtual
        override
        returns (uint[] memory amounts);
}

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();

    let rpc_url = "https://rpc.ankr.com/eth".parse().unwrap();
    let provider = alloy::providers::ProviderBuilder::new().on_http(rpc_url);
    let uniswap_v2 = address!("7a250d5630b4cf539739df2c5dacb4c659f2488d");

    let mut multicall = Multicall::with_provider_chain_id(&provider).await.unwrap();

    let amounts_out = getAmountsOutCall::abi();

    multicall.add_call(
        uniswap_v2,
        &amounts_out,
        &[
            DynSolValue::from(U256::from(1000000000000000000_u128)),
            DynSolValue::Array(vec![
                address!("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2").into(),
                address!("6982508145454Ce325dDbE47a25d4ec3d2311933").into(),
            ]),
        ],
        false,
    );

    let results = multicall.call().await.unwrap();
    println!("{:?}", results);
}

Credits

Dependencies

~53MB
~832K SLoC