#dfinity #ethereum #web3 #graph-protocol #icp

ic-solidity-bindgen

Generates bindings for solidity contracts. Uses web3 under the hood. This is a fork of graphprotocol/solidity-bindgen

25 releases

new 0.1.25 Apr 27, 2025
0.1.21 Jan 4, 2025
0.1.19 Nov 21, 2024
0.1.16 May 22, 2024
0.1.5 Jun 9, 2023

#802 in Magic Beans

Download history 8/week @ 2025-01-08 26/week @ 2025-02-05 4/week @ 2025-02-12 22/week @ 2025-02-19 2/week @ 2025-02-26 19/week @ 2025-03-05 64/week @ 2025-03-12 121/week @ 2025-03-19 121/week @ 2025-03-26 48/week @ 2025-04-02 67/week @ 2025-04-09 62/week @ 2025-04-16 522/week @ 2025-04-23

712 downloads per month

MIT license

23KB
522 lines

ic-solidity-bindgen

This is a tool to generate Rust bindings for Solidity contracts to use with the Internet Computer.

Usage

contract_abis!("../abi");

thread_local! {
    static ORACLE_ADDRESSES: RefCell<BTreeMap<SupportedNetwork,Address>> = RefCell::new(BTreeMap::new());
}

#[update]
#[candid_method(update)]
async fn set_value(symbol: String, value: WrappedU256) {
    struct Dist {
        nw: SupportedNetwork,
        addr: Address,
    }

    for d in ORACLE_ADDRESSES.with(|addresses| {
        addresses
            .borrow()
            .iter()
            .map(|(&k, &v)| Dist { nw: k, addr: v })
            .collect::<Vec<Dist>>()
    }) {
        let context = ctx(d.nw).unwrap();
        let oracle = IPriceOracle::new(d.addr.clone(), &context); // This is the generated binding
        let res = oracle
            .set_price(
                symbol.to_string().clone(),
                value.value(),
                Some(call_options()),
            )
            .await.unwrap();
        ic_cdk::println!("set_value: {:?}", res);
    }
}
fn call_options() -> Options {
    let call_options = CallOptionsBuilder::default()
        .transform(Some(TransformContext {
            function: TransformFunc(candid::Func {
                principal: ic_cdk::api::id(),
                method: "transform_request".to_string(),
            }),
            context: vec![],
        }))
        .max_resp(None)
        .cycles(None)
        .build()
        .unwrap();
    let mut opts = Options::default();
    opts.call_options = Some(call_options);
    opts
}

Dependencies

~9–17MB
~225K SLoC