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"
2
3const buff = await Buff.init({
4 network: "mainnet-beta", // or "devnet" for testing
5 platformId: "your-platform-id",
6 signMessage: (msg) => wallet.signMessage(msg),
7 plan: "sprout", // rounds to nearest $0.10
8 investInto: "BTC", // auto-buy Bitcoin
9 investThreshold: 5, // swap when $5 accumulated
10})
11
12console.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 transaction
2const tx = new Transaction()
3tx.add(/* your swap/mint/transfer instruction */)
4
5// Wrap with Buff — pass the total tx value in USD
6const { transaction, breakdown } = await buff.wrap(tx, userPubkey, {
7 txValueUsd: 47.83
8})
9
10console.log("Round-up:", breakdown.roundUpUsd) // $0.17
11console.log("User invests:", breakdown.userInvestmentUsd) // $0.1687
12console.log("Buff fee:", breakdown.buffFeeUsd) // $0.0013
13console.log("Skipped:", breakdown.skipped) // false
14
15// Sign and send the wrapped transaction as usual
16await 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()
2
3if (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()
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" }]
7
8// User can export their wallet to Phantom
9const privateKey = buff.exportKey()
5

Listen for Events

events.ts
typescript
1buff.events.on("roundUp", ({ breakdown, roundUpCount }) => {
2 showToast("Invested $" + breakdown.roundUpUsd.toFixed(2))
3})
4
5buff.events.on("thresholdReached", ({ state }) => {
6 showToast("Swapping " + state.balanceSol + " SOL → BTC")
7})
8
9buff.events.on("swapExecuted", ({ result }) => {
10 showToast("Bought " + result.asset + "!")
11})
12
13buff.events.on("skipped", ({ txValueUsd }) => {
14 // Exact dollar amount — no round-up
15})
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.