Quick Start

Integrate Buff into your Solana application in 5 minutes.

1

Create a Buff Client

Instantiate the Buff client with your API key and desired configuration. For wallet-based auth, call setWalletAuth after the user signs the auth message.

init.ts
typescript
1import { Buff } from "buff-protocol-sdk"
2
3const buff = new Buff({
4 apiKey: "your-api-key", // or use wallet auth below
5 network: "mainnet-beta", // or "devnet" for testing
6 plan: "sprout", // rounds to nearest $0.10
7 investInto: "BTC", // auto-buy Bitcoin
8 investThreshold: 5, // swap when $5 accumulated
9})
10
11// Optional: wallet-based auth instead of API key
12const authMsg = await buff.getAuthMessage()
13const signature = await wallet.signMessage(authMsg)
14buff.setWalletAuth(wallet.publicKey.toBase58(), signature)
15
16// Derive the user's Buff wallet (server-side derivation)
17const buffWallet = await buff.deriveWallet(signature)
18console.log("Buff wallet:", buffWallet)
2

Get Wrap Instructions

When your user makes a transaction, get the round-up transfer instructions from the server. Add them to your transaction before signing. All fee calculation happens server-side.

wrap.ts
typescript
1// Get round-up instructions for the transaction value
2const { instructions, breakdown } = await buff.getWrapInstructions(
3 47.83, userPubkey, buffWalletPubkey
4)
5
6console.log("Round-up:", breakdown.roundUpUsd) // $0.17
7console.log("User invests:", breakdown.userInvestmentUsd) // $0.1687
8console.log("Buff fee:", breakdown.buffFeeUsd) // $0.0013
9console.log("Skipped:", breakdown.skipped) // false
10
11// Add instructions to your existing transaction
12const tx = new Transaction()
13tx.add(/* your swap/mint/transfer instruction */)
14for (const ix of instructions) tx.add(ix)
15
16// Sign and send the wrapped transaction as usual
17await sendTransaction(tx)
3

Check Accumulator & Swap

After each transaction, check the accumulated balance. When the threshold is reached, build and execute swap transactions via the server.

invest.ts
typescript
1// Check accumulator state
2const state = await buff.getAccumulator(buffWalletPubkey)
3
4if (state.thresholdReached) {
5 // Build swap transactions server-side
6 const { ready, transactions } = await buff.buildSwap(buffWalletPubkey)
7
8 if (ready) {
9 // Sign and execute each swap transaction
10 for (const txBase64 of transactions) {
11 const signed = await wallet.signTransaction(txBase64)
12 await buff.executeSwap(signed)
13 }
14 console.log("Swaps executed!")
15 }
16} else {
17 console.log("Accumulated:", state.balanceUsd, "/ $", state.thresholdUsd)
18}
4

View Portfolio

portfolio.ts
typescript
1const portfolio = await buff.getPortfolio(buffWalletPubkey)
2
3console.log("Total value:", portfolio.totalUsd)
4console.log("Pending SOL:", portfolio.pendingSol)
5console.log("Balances:", portfolio.balances)
6// [{ asset: "BTC", usdValue: 48.20, balance: "0.00068" }]
5

Explore Plans & Prices

plans.ts
typescript
1// Get available plans and their details
2const plans = await buff.getPlans()
3console.log(plans)
4// [{ tier: "seed", roundToUsd: 0.05, feePercent: 1.00 }, ...]
5
6// Get current asset prices
7const prices = await buff.getPrices()
8console.log(prices)
9// { SOL: 150.00, BTC: 71000, ETH: 2100, ... }
10
11// Calculate a round-up without wrapping
12const breakdown = await buff.calculateRoundUp(27.63)
13console.log(breakdown)
14// { roundUpUsd: 0.37, userInvestmentUsd: 0.3672, ... }
Note
The Buff wallet is derived server-side from the user's signature. The treasury address and fee logic are never exposed to the client. All swap routing and execution is handled by the Buff API.