SDK
Go SDK
Use the Buff API from Go via the REST endpoints.
Install
No external dependencies needed — just net/http and encoding/json.
Quick Start
main.go
typescript
1package main23import (4 "bytes"5 "encoding/json"6 "fmt"7 "net/http"8 "io"9)1011const api = "https://buff.finance"12const apiKey = "YOUR_API_KEY"1314func buffPost(path string, body map[string]interface{}) map[string]interface{} {15 data, _ := json.Marshal(body)16 req, _ := http.NewRequest("POST", api+path, bytes.NewBuffer(data))17 req.Header.Set("Content-Type", "application/json")18 req.Header.Set("x-api-key", apiKey)19 resp, _ := http.DefaultClient.Do(req)20 defer resp.Body.Close()21 raw, _ := io.ReadAll(resp.Body)22 var result map[string]interface{}23 json.Unmarshal(raw, &result)24 return result["data"].(map[string]interface{})25}2627func main() {28 // Calculate round-up29 data := buffPost("/api/roundup", map[string]interface{}{30 "txValueUsd": 27.63,31 "plan": "sprout",32 })33 fmt.Printf("Round-up: $%v\n", data["roundUpUsd"]) // $0.073435 // Get wrap instructions (server builds transfers with fees)36 wrap := buffPost("/api/wrap", map[string]interface{}{37 "txValueUsd": 27.63,38 "userPubkey": "YOUR_PUBKEY",39 "buffWalletPubkey": "BUFF_WALLET",40 "plan": "sprout",41 })42 breakdown := wrap["breakdown"].(map[string]interface{})43 fmt.Printf("Fee: %v lamports\n", breakdown["buffFeeLamports"])4445 // Build swap46 swap := buffPost("/api/swap/build", map[string]interface{}{47 "buffWalletPubkey": "BUFF_WALLET",48 "targetAsset": "BTC",49 "threshold": 5,50 })51 fmt.Printf("Ready: %v\n", swap["ready"])52}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 Go client just calls the REST API — stdlib only, no external dependencies. Auth via API key or wallet signature headers.