switchboard-evm

Crates.ioswitchboard-evm
lib.rsswitchboard-evm
version0.5.18
sourcesrc
created_at2023-07-13 15:17:47.289773
updated_at2023-11-16 03:23:52.073252
descriptionA Rust library to interact with Switchboard on EVM based chains.
homepagehttps://switchboard.xyz
repositoryhttps://github.com/switchboard-xyz/evm-sdk/tree/main/rust/switchboard-evm
max_upload_size
id915442
size1,081,039
Jackson Jessup (jessupjn)

documentation

README

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
}
Commit count: 0

cargo fmt