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"23const buff = new Buff({4 apiKey: "your-api-key", // or use wallet auth below5 network: "mainnet-beta", // or "devnet" for testing6 plan: "sprout", // rounds to nearest $0.107 investInto: "BTC", // auto-buy Bitcoin8 investThreshold: 5, // swap when $5 accumulated9})1011// Optional: wallet-based auth instead of API key12const authMsg = await buff.getAuthMessage()13const signature = await wallet.signMessage(authMsg)14buff.setWalletAuth(wallet.publicKey.toBase58(), signature)1516// 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 value2const { instructions, breakdown } = await buff.getWrapInstructions(3 47.83, userPubkey, buffWalletPubkey4)56console.log("Round-up:", breakdown.roundUpUsd) // $0.177console.log("User invests:", breakdown.userInvestmentUsd) // $0.16878console.log("Buff fee:", breakdown.buffFeeUsd) // $0.00139console.log("Skipped:", breakdown.skipped) // false1011// Add instructions to your existing transaction12const tx = new Transaction()13tx.add(/* your swap/mint/transfer instruction */)14for (const ix of instructions) tx.add(ix)1516// Sign and send the wrapped transaction as usual17await 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 state2const state = await buff.getAccumulator(buffWalletPubkey)34if (state.thresholdReached) {5 // Build swap transactions server-side6 const { ready, transactions } = await buff.buildSwap(buffWalletPubkey)78 if (ready) {9 // Sign and execute each swap transaction10 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)23console.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 details2const plans = await buff.getPlans()3console.log(plans)4// [{ tier: "seed", roundToUsd: 0.05, feePercent: 1.00 }, ...]56// Get current asset prices7const prices = await buff.getPrices()8console.log(prices)9// { SOL: 150.00, BTC: 71000, ETH: 2100, ... }1011// Calculate a round-up without wrapping12const 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.