![Switchboard Logo](https://github.com/switchboard-xyz/core-sdk/raw/main/website/static/img/icons/switchboard/avatar.png) # switchboard-evm > A Rust library to interact with Switchboard on EVM based chains. [![Crates.io Badge](https://img.shields.io/crates/v/switchboard-evm?label=switchboard-evm&logo=rust)](https://crates.io/crates/switchboard-evm) [![Discord Badge](https://img.shields.io/discord/841525135311634443?color=blueviolet&logo=discord&logoColor=white)](https://discord.gg/switchboardxyz) [![Twitter Badge](https://img.shields.io/twitter/follow/switchboardxyz?label=Follow+Switchboard)](https://twitter.com/switchboardxyz)

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:

bash cargo add switchboard-evm

Or add the following line to your Cargo.toml:

toml [dependencies] switchboard-evm = "0.3.10"

Usage

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

```rust // Generate your contract's ABI abigen!(Receiver, r#"[ function callback(int256, uint256) ]"#,);

[derive(Debug, Deserialize)]

pub struct DeribitRespnseInner { pub mark_iv: f64, pub timestamp: u64, }

[derive(Debug, Deserialize)]

pub struct DeribitResponse { pub result: DeribitRespnseInner, }

[tokio::main(worker_threads = 12)]

async fn main() -> Result<(), Box> { // --- Initialize clients --- let functionrunner = EVMFunctionRunner::new()?; let client = functionrunner.get_client(None).await?;

let receiver: Address = env!("EXAMPLE_PROGRAM").parse()?;
let receiver_contract = Receiver::new(receiver, client.into());

// --- Logic Below ---
let url = "https://www.deribit.com/api/v2/public/get_order_book?instrument_name=ETH-29SEP23-2000-C";
let derebit_response: DeribitResponse = reqwest::get(url).await?.json().await?;

let timestamp = derebit_response.result.timestamp.into();
let mut mark_iv = Decimal::from_f64(derebit_response.result.mark_iv).unwrap();
mark_iv.rescale(8);

// --- Send the callback to the contract with Switchboard verification ---
let callback = receiver_contract.callback(mark_iv.mantissa().into(), timestamp);
let expiration = (Utc::now().timestamp() + 120).into();
let gas_limit = 5_500_000.into();
function_runner.emit(receiver, expiration, gas_limit, vec![callback])?;
Ok(())

} ```