Quick Start
Integrate Buff into your Solana application in 5 minutes.
1
Initialize the SDK
The user signs a message to derive their deterministic Buff wallet. Same signature always produces the same wallet — no storage needed.
init.ts
typescript
1import { Buff } from "@buff/sdk"23const buff = await Buff.init({4 network: "mainnet-beta", // or "devnet" for testing5 platformId: "your-platform-id",6 signMessage: (msg) => wallet.signMessage(msg),7 plan: "sprout", // rounds to nearest $0.108 investInto: "BTC", // auto-buy Bitcoin9 investThreshold: 5, // swap when $5 accumulated10})1112console.log("Buff wallet:", buff.getWalletAddress())2
Wrap Transactions
When your user makes a transaction, wrap it with Buff. The SDK adds two transfer instructions — one for the user's investment, one for the Buff platform fee.
wrap.ts
typescript
1// Your existing transaction2const tx = new Transaction()3tx.add(/* your swap/mint/transfer instruction */)45// Wrap with Buff — pass the total tx value in USD6const { transaction, breakdown } = await buff.wrap(tx, userPubkey, {7 txValueUsd: 47.838})910console.log("Round-up:", breakdown.roundUpUsd) // $0.1711console.log("User invests:", breakdown.userInvestmentUsd) // $0.168712console.log("Buff fee:", breakdown.buffFeeUsd) // $0.001313console.log("Skipped:", breakdown.skipped) // false1415// Sign and send the wrapped transaction as usual16await sendTransaction(transaction)3
Check & Auto-Invest
After each transaction, check if the accumulated balance has reached the threshold. If yes, Buff swaps to the target asset via Jupiter.
invest.ts
typescript
1const { state, swap, quote } = await buff.checkAndInvest()23if (swap) {4 console.log("Swapped!", swap.txSignature)5 console.log("Input:", swap.inputSol, "SOL →", swap.asset)6} else {7 console.log("Accumulated:", state.balanceUsd, "/ $", state.thresholdUsd)8}4
View Portfolio
portfolio.ts
typescript
1const portfolio = await buff.getPortfolio()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" }]78// User can export their wallet to Phantom9const privateKey = buff.exportKey()5
Listen for Events
events.ts
typescript
1buff.events.on("roundUp", ({ breakdown, roundUpCount }) => {2 showToast("Invested $" + breakdown.roundUpUsd.toFixed(2))3})45buff.events.on("thresholdReached", ({ state }) => {6 showToast("Swapping " + state.balanceSol + " SOL → BTC")7})89buff.events.on("swapExecuted", ({ result }) => {10 showToast("Bought " + result.asset + "!")11})1213buff.events.on("skipped", ({ txValueUsd }) => {14 // Exact dollar amount — no round-up15})Note
The Buff wallet is fully non-custodial. Users can export the private key at any time and import it into Phantom, Solflare, or any Solana wallet. Buff never has access to the funds.