---
title: "Rust SDK Quickstart"
description: "Install and use the Hadron Rust SDK in a few minutes."
---

## Install

```bash
cargo add hadron-sdk
```

The SDK requires `solana-sdk` for `Pubkey` and `Instruction` types:

```bash
cargo add solana-sdk
```

## Load a pool from account data

The Rust SDK is sync-first — you provide raw account data and it decodes everything locally.

```rust
use hadron_sdk::hadron::Hadron;
use solana_sdk::pubkey::Pubkey;

let pool_address: Pubkey = "REPLACE_WITH_POOL_ADDRESS".parse().unwrap();

// Fetch account data however you like (RPC, Geyser, etc.)
// let config_data  = rpc.get_account_data(&pool_address)?;
// let oracle_data  = rpc.get_account_data(&oracle_pda)?;
// let meta_data    = rpc.get_account_data(&curve_meta_pda)?;
// let prefabs_data = rpc.get_account_data(&curve_prefabs_pda)?;

let pool = Hadron::from_accounts(
    pool_address,
    &config_data,
    &oracle_data,
    &meta_data,
    &prefabs_data,
)?;
```

<Tip>
Enable the `rpc` feature (`cargo add hadron-sdk --features rpc`) for a convenience
`Hadron::load(&rpc_client, &pool_address)` method that fetches accounts over RPC.
</Tip>

## Read core state

```rust
let midprice = pool.get_midprice();       // f64
let spread   = pool.get_spread_factor();  // f64, e.g. 0.9995 = 5 bps
let slots    = pool.get_active_curve_slots();

println!("midprice={midprice} spread={spread} slots={slots:?}");
```

## Build a swap instruction

```rust
use hadron_sdk::types::SwapParams;
use solana_sdk::pubkey::Pubkey;

let user: Pubkey = "REPLACE_WITH_USER_PUBKEY".parse().unwrap();
let fee_recipient: Pubkey = "REPLACE_WITH_FEE_RECIPIENT".parse().unwrap();

let swap_ix = pool.swap(&user, &SwapParams {
    is_x: true,               // true = sell X for Y, false = sell Y for X
    amount_in: 1_000_000,
    min_out: 0,                // set > 0 for slippage protection
    fee_recipient,
    expiration: None,
});
```