API
Accumulate & Swap
Check accumulated balance, get swap quotes, build and execute swaps — all via the Buff API.
Get Accumulator State
types.ts
typescript
1async getAccumulator(address: string): Promise<AccumulatorState>23interface AccumulatorState {4 balanceSol: number // Buff wallet SOL balance5 balanceUsd: number // In USD (real-time price)6 remaining: number // USD remaining until threshold7 thresholdReached: boolean8 thresholdUsd: number // Configured threshold9 solPriceUsd: number // Current SOL price10}Get Swap Quote
types.ts
typescript
1async getSwapQuote(2 inputLamports: number,3 targetAsset: SupportedAsset4): Promise<SwapQuote>56interface SwapQuote {7 inputSol: number8 outputAmount: string9 outputMint: string10 priceImpact: string11 route: string12}Build & Execute Swaps
types.ts
typescript
1// Build swap transactions server-side2async buildSwap(buffWalletPubkey: string): Promise<{3 ready: boolean4 balanceSol: number5 balanceUsd: number6 threshold: number7 transactions: Array<{8 asset: string9 pct: number10 inputLamports: number11 transaction: string // base64 unsigned tx — sign then executeSwap()12 quote: SwapQuote13 }>14}>1516// Execute a signed swap transaction17async executeSwap(signedTxBase64: string): Promise<{18 txSignature: string19 confirmed: boolean20}>Example
invest.ts
typescript
1// Check accumulator state2const state = await buff.getAccumulator(buffWalletPubkey)34if (!state.thresholdReached) {5 console.log("Accumulated: $" + state.balanceUsd.toFixed(2))6 console.log("Need: $" + (state.thresholdUsd - state.balanceUsd).toFixed(2))7 return8}910// Build swap transactions (server handles routing via Jupiter)11const { ready, transactions } = await buff.buildSwap(buffWalletPubkey)1213if (ready) {14 for (const txBase64 of transactions) {15 // Sign the transaction with the Buff wallet16 const signed = await signTransaction(txBase64)17 const result = await buff.executeSwap(signed)18 console.log("Swapped →", result.asset, "tx:", result.txSignature)19 }20}Note
All swap routing happens server-side via Jupiter. The client only signs and submits the pre-built transactions. A 0.01 SOL reserve is kept in the Buff wallet for future transaction fees.
Preview a Swap Quote
quote.ts
typescript
1// Get a swap quote without executing2const quote = await buff.getSwapQuote(50000000, "BTC") // 0.05 SOL in lamports34console.log("Would swap:", quote.inputSol, "SOL")5console.log("Expected output:", quote.outputAmount)6console.log("Route:", quote.route)7console.log("Price impact:", quote.priceImpact + "%")