Doppler
SDKs

Rust

Build Doppler oracle update transactions from Rust clients.

The Rust client is generated for your payload schema. It gives you typed payload structs, program constants, update instructions, and a transaction builder.

Generate the SDK

Doppler does not publish this client to crates.io. Generate it with the generate command after initializing your payload schema:

npx @blueshift-gg/doppler-cli generate ./payload.ts \
  --rust-sdk ./generated/sdk/rust

For a config named price-feed, the crate package name is price-feed-sdk. Import it in Rust as price_feed_sdk.

Add to Your Application

Add the generated crate path to your application Cargo.toml, plus any Solana client crates your app uses:

[dependencies]
price-feed-sdk = { path = "./generated/sdk/rust" }
solana-client = "4.0.0"

The generated SDK Cargo.toml already depends on the Solana crates used by UpdateInstruction and transaction::Builder. Add solana-client only when your application sends transactions through RpcClient.

Payload Type

The generator emits a payload struct for your schema. For a default price: u64 feed named price-feed, the type is PriceFeedPayload:

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PriceFeedPayload {
    pub price: u64,
}

Oracle data is generic over that payload type:

use price_feed_sdk::{Oracle, PriceFeedPayload};

let oracle = Oracle::<PriceFeedPayload> {
    sequence: 1_725_000_000,
    payload: PriceFeedPayload {
        price: 42_000_000,
    },
};

Struct and module names are derived from your generator config name.

Build an Update Instruction

use price_feed_sdk::{Oracle, PriceFeedPayload, UpdateInstruction, ID};
use solana_instruction::Instruction;
use solana_pubkey::Pubkey;
use solana_signer::Signer;

let update_ix: Instruction = UpdateInstruction {
    admin: admin.pubkey(),
    oracle_pubkey,
    oracle: Oracle::<PriceFeedPayload> {
        sequence: 1_725_000_000,
        payload: PriceFeedPayload {
            price: 42_000_000,
        },
    },
}
.into();

Build and Send a Transaction

The generated SDK includes transaction::Builder, which prepends compute-budget instructions before oracle updates:

use price_feed_sdk::{
    transaction::Builder,
    Oracle, PriceFeedPayload,
};
use solana_client::rpc_client::RpcClient;
use solana_keypair::Keypair;
use solana_signer::Signer;

fn update_price(
    client: &RpcClient,
    admin: &Keypair,
    oracle_pubkey: solana_pubkey::Pubkey,
) -> Result<(), Box<dyn std::error::Error>> {
    let recent_blockhash = client.get_latest_blockhash()?;

    let tx = Builder::new(admin)
        .add_oracle_update(
            oracle_pubkey,
            Oracle::<PriceFeedPayload> {
                sequence: 1_725_000_000,
                payload: PriceFeedPayload {
                    price: 42_000_000,
                },
            },
        )
        .with_unit_price(1_000)
        .build(recent_blockhash);

    let signature = client.send_and_confirm_transaction(&tx)?;
    println!("Oracle updated: {signature}");

    Ok(())
}

On this page