Guide
React / Next.js
Full integration guide with Solana Wallet Adapter and Reown (WalletConnect).
Install
$
npm install buff-protocol-sdk @solana/wallet-adapter-react @solana/wallet-adapter-walletsCopyProvider
BuffProvider.tsx
typescript
1"use client"2import { createContext, useContext, useState, useEffect } from "react"3import { useWallet } from "@solana/wallet-adapter-react"4import { Buff } from "buff-protocol-sdk"56const BuffContext = createContext<Buff | null>(null)78export function BuffProvider({ children, apiKey }: {9 children: React.ReactNode10 apiKey: string11}) {12 const { signMessage, publicKey } = useWallet()13 const [buff, setBuff] = useState<Buff | null>(null)1415 useEffect(() => {16 if (!signMessage || !publicKey) return1718 const b = new Buff({19 apiKey,20 plan: "sprout",21 investInto: "BTC",22 })2324 // Authenticate with wallet signature25 const msg = new TextEncoder().encode("Sign in to Buff")26 signMessage(msg).then((sig) => {27 b.setWalletAuth(publicKey.toBase58(), Buffer.from(sig).toString("base64"))28 setBuff(b)29 })30 }, [signMessage, publicKey, apiKey])3132 return (33 <BuffContext.Provider value={buff}>34 {children}35 </BuffContext.Provider>36 )37}3839export const useBuff = () => useContext(BuffContext)Wrapping Transactions
useSwap.tsx
typescript
1import { useBuff } from "./BuffProvider"2import { useWallet } from "@solana/wallet-adapter-react"34function SwapButton({ tx, valueUsd, buffWalletPubkey }) {5 const buff = useBuff()6 const { publicKey, sendTransaction } = useWallet()78 const handleSwap = async () => {9 if (!buff || !publicKey) return1011 // Get round-up instructions from the API12 const { instructions, breakdown } = await buff.getWrapInstructions(13 valueUsd, publicKey.toBase58(), buffWalletPubkey14 )1516 if (!breakdown.skipped) {17 toast("Investing $" + breakdown.roundUpUsd.toFixed(2))18 }1920 // Add Buff instructions to your transaction, then send21 for (const ix of instructions) tx.add(ix)22 await sendTransaction(tx, connection)2324 // Build and execute the swap when threshold is reached25 const { ready, transactions } = await buff.buildSwap(buffWalletPubkey)26 if (ready) {27 for (const swapTx of transactions) {28 const signed = await signTransaction(swapTx)29 await buff.executeSwap(Buffer.from(signed.serialize()).toString("base64"))30 }31 toast("Swap executed!")32 }33 }3435 return <button onClick={handleSwap}>Swap</button>36}Note
Both approaches use the same Buff SDK. Authentication is handled via API key or wallet signature headers — no signMessage callback needed. The SDK makes HTTP calls to the buff.finance API.