#evm #switchboard #solidity #oracle

switchboard-evm

A Rust library to interact with Switchboard on EVM based chains

59 releases (4 breaking)

0.5.18 Nov 16, 2023
0.5.13 Oct 31, 2023
0.3.5 Jul 31, 2023

#4 in #switchboard

Download history 1/week @ 2024-07-22 1/week @ 2024-09-23 2/week @ 2024-09-30

559 downloads per month

MIT license

1MB
21K SLoC

Switchboard Logo

switchboard-evm

A Rust library to interact with Switchboard on EVM based chains.

Crates.io Badge

Discord Badge

Twitter Badge

Typedocs: docs.rs/switchboard-evm

EVM SDK: github.com/switchboard-xyz/evm-sdk

Switchboard Documentation: docs.switchboard.xyz

Install

Run the following Cargo command in your project directory:

cargo add switchboard-evm

Or add the following line to your Cargo.toml:

[dependencies]
switchboard-evm = "0.5.15"

Usage

Here's an example of using the EvmFunctionRunner inside a Switchboard Function:

/// Required
static CLIENT_URL: &str = "https://goerli-rollup.arbitrum.io/rpc";
// Generate your contract's ABI
abigen!(Receiver, r#"[ function callback(uint256) ]"#,);

#[derive(EthAbiType, EthAbiCodec, Default, Debug, Clone)]
pub struct Params {
    callback: Address,
}

#[sb_function(expiration_seconds = 120, gas_limit = 5_500_000)]
async fn sb_function(client: SbMiddleware, _call_id: Address, params: Params) -> SbResult {
    let receiver_contract = Receiver::new(params.callback, client.into());
    let mut random = [0u8; 32];
    Gramine::read_rand(random.as_mut_slice()).map_err(|_| SbError::SgxRandReadFail)?;
    Ok(vec![receiver_contract.callback(U256::from_little_endian(&random))])
}

#[sb_error]
pub enum SbError {
    SgxRandReadFail
}

Dependencies

~34–51MB
~1M SLoC