Guide
React / Next.js
Full integration guide with Solana Wallet Adapter and Reown (WalletConnect).
Install
$
npm install @buff/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/sdk"56const BuffContext = createContext<Buff | null>(null)78export function BuffProvider({ children, platformId }: {9 children: React.ReactNode10 platformId: string11}) {12 const { signMessage, publicKey } = useWallet()13 const [buff, setBuff] = useState<Buff | null>(null)1415 useEffect(() => {16 if (!signMessage || !publicKey) return1718 Buff.init({19 platformId,20 signMessage: (msg) => signMessage(msg),21 plan: "sprout",22 investInto: "BTC",23 }).then(setBuff)24 }, [signMessage, publicKey, platformId])2526 return (27 <BuffContext.Provider value={buff}>28 {children}29 </BuffContext.Provider>30 )31}3233export const useBuff = () => useContext(BuffContext)Wrapping Transactions
useSwap.tsx
typescript
1import { useBuff } from "./BuffProvider"2import { useWallet } from "@solana/wallet-adapter-react"34function SwapButton({ tx, valueUsd }) {5 const buff = useBuff()6 const { publicKey, sendTransaction } = useWallet()78 const handleSwap = async () => {9 if (!buff || !publicKey) return1011 const { transaction, breakdown } = await buff.wrap(12 tx, publicKey, { txValueUsd: valueUsd }13 )1415 if (!breakdown.skipped) {16 toast("Investing $" + breakdown.roundUpUsd.toFixed(2))17 }1819 await sendTransaction(transaction, connection)2021 const { swap } = await buff.checkAndInvest()22 if (swap) toast("Bought " + swap.asset + "!")23 }2425 return <button onClick={handleSwap}>Swap</button>26}Note
Both approaches produce the same Buff wallet from the same main wallet. The SDK's signMessage option is framework-agnostic — it just needs a function that takes Uint8Array and returns a signed Uint8Array.