Crates.io | switchboard-evm |
lib.rs | switchboard-evm |
version | 0.5.18 |
source | src |
created_at | 2023-07-13 15:17:47.289773 |
updated_at | 2023-11-16 03:23:52.073252 |
description | A Rust library to interact with Switchboard on EVM based chains. |
homepage | https://switchboard.xyz |
repository | https://github.com/switchboard-xyz/evm-sdk/tree/main/rust/switchboard-evm |
max_upload_size | |
id | 915442 |
size | 1,081,039 |
A Rust library to interact with Switchboard on EVM based chains.
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"
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
}