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 main
2
3import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "net/http"
8 "io"
9)
10
11const api = "https://buff.finance"
12const apiKey = "YOUR_API_KEY"
13
14func 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}
26
27func main() {
28 // Calculate round-up
29 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.07
34
35 // 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"])
44
45 // Build swap
46 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

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 Go client just calls the REST API — stdlib only, no external dependencies. Auth via API key or wallet signature headers.