5 releases

new 0.1.4 Nov 22, 2024
0.1.3 Oct 2, 2024
0.1.2 Sep 20, 2024
0.1.1 Sep 3, 2024
0.1.0 Sep 3, 2024

#517 in Magic Beans

Download history 241/week @ 2024-09-01 13/week @ 2024-09-08 109/week @ 2024-09-15 30/week @ 2024-09-22 170/week @ 2024-09-29 13/week @ 2024-10-06 8/week @ 2024-10-13 1/week @ 2024-10-20 15/week @ 2024-11-03 1/week @ 2024-11-10 114/week @ 2024-11-17

130 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.1.4"

Example

use alloy_multicall::Multicall;
use alloy_sol_types::{sol, JsonAbiExt};
use alloy_primitives::{address, U256};
use alloy_dyn_abi::DynSolValue;

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() {
    let rpc_url = "https://rpc.ankr.com/eth".parse().unwrap();
    let provider = alloy_provider::ProviderBuilder::new().on_http(rpc_url);  
    let uniswap_v2 = address!("7a250d5630b4cf539739df2c5dacb4c659f2488d");


    let mut multicall = Multicall::new(provider.clone(), None).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

~31–44MB
~808K SLoC