Skip to content

Instantly share code, notes, and snippets.

@mgild
Created May 29, 2025 19:25
Show Gist options
  • Save mgild/6c1848d8172319c43f8d12482786a384 to your computer and use it in GitHub Desktop.
Save mgild/6c1848d8172319c43f8d12482786a384 to your computer and use it in GitHub Desktop.
use switchboard_on_demand_client::gateway::Gateway;
use switchboard_on_demand_client::FetchUpdateParams;
use switchboard_on_demand_client::PullFeed;
use switchboard_on_demand_client::SbContext;
use std::sync::Arc;
use std::str::FromStr;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Connect to the Solana Devnet
let rpc_url = std::env::var("RPC_URL").unwrap();
let rpc_client = RpcClient::new(rpc_url.to_string());
// Initialize the Gateway
let gateway = Gateway::new("https://141.95.85.92.xip.switchboard-oracles.xyz/mainnet".into());
// Specify the feed public key
let feed_pubkey = Pubkey::from_str("AJ1C3CpVrWgQFNmxgfvSM81XqzE738BagvXz6hBPWVHL")?;
// Fetch the latest feed data
let ctx = SbContext::new();
let f = PullFeed::fetch_update_ix(ctx, &rpc_client, FetchUpdateParams {
feed: feed_pubkey,
gateway: gateway.clone(),
payer: Pubkey::default(),
..Default::default()
}).await?;
// Display the fetched data
println!("Fetched feed data: {:?}", f);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment