SDK
Rust SDK
Use the Buff API from Rust via the REST endpoints.
Install
$
cargo add reqwest serde_json tokio --features tokio/full,reqwest/jsonCopyQuick Start
main.rs
typescript
1use reqwest::Client;2use serde_json::{json, Value};34const API: &str = "https://buff.finance";5const API_KEY: &str = "YOUR_API_KEY";67#[tokio::main]8async fn main() -> Result<(), Box<dyn std::error::Error>> {9 let client = Client::new();1011 // Calculate round-up12 let url = format!("{}/api/roundup", API);13 let res: Value = client.post(&url)14 .header("x-api-key", API_KEY)15 .json(&json!({"txValueUsd": 27.63, "plan": "sprout"}))16 .send().await?.json().await?;17 println!("Round-up: {}", res["data"]["roundUpUsd"]); // 0.071819 // Get wrap instructions (server builds transfers with fees)20 let url = format!("{}/api/wrap", API);21 let res: Value = client.post(&url)22 .header("x-api-key", API_KEY)23 .json(&json!({24 "txValueUsd": 27.63,25 "userPubkey": "YOUR_PUBKEY",26 "buffWalletPubkey": "BUFF_WALLET",27 "plan": "sprout"28 }))29 .send().await?.json().await?;30 let ix = res["data"]["instructions"].as_array().unwrap();31 println!("Instructions: {}", ix.len());3233 // Build swap when threshold reached34 let url = format!("{}/api/swap/build", API);35 let res: Value = client.post(&url)36 .header("x-api-key", API_KEY)37 .json(&json!({38 "buffWalletPubkey": "BUFF_WALLET",39 "targetAsset": "BTC",40 "threshold": 541 }))42 .send().await?.json().await?;43 println!("Ready: {}", res["data"]["ready"]);4445 Ok(())46}Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
| POST /api/roundup | Authenticated | Calculate round-up breakdown |
| POST /api/wrap | Authenticated | Get transfer instructions with fees enforced |
| POST /api/swap/build | Authenticated | Build Jupiter swap transactions |
| POST /api/swap/execute | Authenticated | Execute signed swap transaction |
| GET /api/portfolio/:addr | Public | Get wallet token balances |
| GET /api/accumulator/:addr | Public | Check balance vs threshold |
| GET /api/plans | Public | Get plan tiers and config |
| GET /api/price | Public | Get current crypto prices |
Note
All fee logic runs server-side. The Rust client just calls the REST API. Auth via API key or wallet signature headers.