API
Events
Subscribe to SDK events for real-time feedback on round-ups, swaps, and errors.
Available Events
| Event | Fires when | Data |
|---|---|---|
| roundUp | A transaction is wrapped with a round-up | { breakdown, roundUpCount } |
| skipped | Transaction was an exact match — no charge | { txValueUsd, reason } |
| thresholdReached | Accumulated balance hits the threshold | { state } |
| swapExecuted | Jupiter swap completed successfully | { result, quote } |
| swapFailed | Jupiter swap failed | { error, inputLamports, asset } |
| priceUpdated | SOL price was fetched/refreshed | { solPriceUsd } |
Usage
events.ts
typescript
1// Subscribe2buff.events.on("roundUp", ({ breakdown, roundUpCount }) => {3 showNotification(4 "Invested $" + breakdown.userInvestmentUsd.toFixed(2) +5 " (round-up #" + roundUpCount + ")"6 )7})89buff.events.on("thresholdReached", ({ state }) => {10 showNotification(11 "Threshold reached! $" + state.balanceUsd.toFixed(2) +12 " ready to invest"13 )14})1516buff.events.on("swapExecuted", ({ result, quote }) => {17 showNotification(18 "Bought " + result.asset + " with " +19 result.inputSol.toFixed(4) + " SOL"20 )21})2223buff.events.on("swapFailed", ({ error, asset }) => {24 showError("Failed to buy " + asset + ": " + error.message)25})2627buff.events.on("skipped", ({ txValueUsd }) => {28 // Exact dollar amount — no round-up needed29})3031buff.events.on("priceUpdated", ({ solPriceUsd }) => {32 updatePriceDisplay(solPriceUsd)33})3435// Unsubscribe36const handler = (data) => console.log(data)37buff.events.on("roundUp", handler)38buff.events.off("roundUp", handler)React Example
useBuffEvents.tsx
typescript
1function useBuffEvents(buff: Buff | null) {2 const [lastRoundUp, setLastRoundUp] = useState(null)3 const [swapCount, setSwapCount] = useState(0)45 useEffect(() => {6 if (!buff) return78 const onRoundUp = (data) => setLastRoundUp(data.breakdown)9 const onSwap = () => setSwapCount(c => c + 1)1011 buff.events.on("roundUp", onRoundUp)12 buff.events.on("swapExecuted", onSwap)1314 return () => {15 buff.events.off("roundUp", onRoundUp)16 buff.events.off("swapExecuted", onSwap)17 }18 }, [buff])1920 return { lastRoundUp, swapCount }21}