SDK

Rust SDK

Use the Buff API from Rust via the REST endpoints.

Install

$cargo add reqwest serde_json tokio --features tokio/full,reqwest/jsonCopy

Quick Start

main.rs
typescript
1use reqwest::Client;
2use serde_json::{json, Value};
3
4const API: &str = "https://buff.finance";
5const API_KEY: &str = "YOUR_API_KEY";
6
7#[tokio::main]
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let client = Client::new();
10
11 // Calculate round-up
12 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.07
18
19 // 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());
32
33 // Build swap when threshold reached
34 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": 5
41 }))
42 .send().await?.json().await?;
43 println!("Ready: {}", res["data"]["ready"]);
44
45 Ok(())
46}

Endpoints

EndpointMethodPurpose
POST /api/roundupAuthenticatedCalculate round-up breakdown
POST /api/wrapAuthenticatedGet transfer instructions with fees enforced
POST /api/swap/buildAuthenticatedBuild Jupiter swap transactions
POST /api/swap/executeAuthenticatedExecute signed swap transaction
GET /api/portfolio/:addrPublicGet wallet token balances
GET /api/accumulator/:addrPublicCheck balance vs threshold
GET /api/plansPublicGet plan tiers and config
GET /api/pricePublicGet 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.