#ethereum #dfinity #icp #bindings-generator #web3 #rpc

ic-solidity-bindgen

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

15 releases

new 0.1.15 May 1, 2024
0.1.14 Apr 30, 2024
0.1.12 Mar 5, 2024
0.1.11 Jan 17, 2024
0.1.5 Jun 9, 2023

#2143 in Magic Beans

Download history 35/week @ 2024-01-08 102/week @ 2024-01-15 100/week @ 2024-01-22 81/week @ 2024-01-29 34/week @ 2024-02-05 45/week @ 2024-02-12 41/week @ 2024-02-19 135/week @ 2024-02-26 356/week @ 2024-03-04 56/week @ 2024-03-11 72/week @ 2024-03-18 115/week @ 2024-04-01 41/week @ 2024-04-08 133/week @ 2024-04-22

289 downloads per month

MIT license

17KB
362 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

~8–17MB
~209K SLoC