API
buff.getWrapInstructions()
Get round-up transfer instructions from the Buff API to add to your transaction.
Signature
types.ts
typescript
1async getWrapInstructions(2 txValueUsd: number,3 userPubkey: string,4 buffWalletPubkey: string5): Promise<{ instructions: string[]; breakdown: RoundUpBreakdown }>Parameters
| Param | Type | Description |
|---|---|---|
| txValueUsd | number | Total transaction value in USD (the amount being swapped/sent/minted) |
| userPubkey | string | The user's main wallet public key |
| buffWalletPubkey | string | The user's Buff wallet public key (from deriveWallet) |
Returns
An object with transfer instructions to append to your transaction, plus a breakdown of the round-up calculation. All fee logic is computed server-side — the treasury address is never exposed to the client.
| Instruction | Destination | Amount |
|---|---|---|
| Transfer 1 | User's Buff wallet | Round-up minus Buff fee |
| Transfer 2 | Buff treasury (hidden) | Buff platform fee |
RoundUpBreakdown
breakdown.ts
typescript
1interface RoundUpBreakdown {2 txValueUsd: number // Original tx value3 roundToUsd: number // Plan's increment4 roundedToUsd: number // Next boundary5 roundUpUsd: number // Spare change amount6 buffFeePercent: number // Buff fee rate7 buffFeeUsd: number // Buff takes8 userInvestmentUsd: number // User gets9 roundUpLamports: number // Total in lamports10 userInvestmentLamports: number // User portion in lamports11 buffFeeLamports: number // Fee portion in lamports12 solPriceUsd: number // SOL price used13 skipped: boolean // true if exact match14 capped: boolean // true if ceiling applied15}Calculate Without Wrapping
calculate.ts
typescript
1// Preview the round-up without generating instructions2const breakdown = await buff.calculateRoundUp(47.83)34console.log("Round-up would be: $" + breakdown.roundUpUsd)5console.log("User would invest: $" + breakdown.userInvestmentUsd)6console.log("Buff fee: $" + breakdown.buffFeeUsd)Example
wrap.ts
typescript
1const { instructions, breakdown } = await buff.getWrapInstructions(2 47.83, userPubkey, buffWalletPubkey3)45if (breakdown.skipped) {6 console.log("Exact dollar — no round-up")7} else {8 console.log("Round-up: $" + breakdown.roundUpUsd)910 // Add instructions to your transaction11 const tx = new Transaction()12 tx.add(/* your swap instruction */)13 for (const ix of instructions) tx.add(ix)1415 // Sign and send as usual16 await sendTransaction(tx)17}Note
If the transaction value is an exact multiple of the plan increment (e.g. $2.00 on Sprout), getWrapInstructions() returns empty instructions with skipped: true in the breakdown.