API
new Buff()
Create a Buff client instance — configure auth, plan, and investment preferences.
Signature
types.ts
typescript
1new Buff(options: BuffOptions): BuffParameters
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | — | API key for authentication (alternative to wallet auth) |
| network | 'mainnet-beta' | 'devnet' | 'mainnet-beta' | Solana network |
| plan | 'seed' | 'sprout' | 'tree' | 'forest' | 'sprout' | Round-up plan tier |
| investInto | SupportedAsset | 'BTC' | Single target asset (use allocations for multi-asset) |
| allocations | Allocation[] | [{asset:'BTC',pct:100}] | Portfolio split — e.g. [{asset:'BTC',pct:60},{asset:'ETH',pct:40}] |
| investThreshold | number | 5 | USD threshold before swapping |
| slippageBps | number | 100 | Slippage tolerance (100 = 1%) |
Authentication
Buff supports two auth methods: API key (for agents/backends) or wallet signature (for browser-based apps).
auth.ts
typescript
1// Option 1: API key auth (set in constructor or later)2const buff = new Buff({ apiKey: "your-api-key" })34// Option 2: Wallet signature auth5const buff = new Buff({ plan: "sprout" })6const authMsg = await buff.getAuthMessage()7const signature = await wallet.signMessage(authMsg)8buff.setWalletAuth(wallet.publicKey.toBase58(), signature)910// Switch API key at runtime11buff.setApiKey("new-api-key")Returns
A Buff instance. Unlike the old Buff.init(), the constructor is synchronous — no wallet signing required at creation time.
Example
init.ts
typescript
1import { Buff } from "buff-protocol-sdk"23// Single asset — 100% BTC4const buff = new Buff({5 apiKey: "my-api-key",6 investInto: "BTC",7})89// Multi-asset portfolio split10const buff = new Buff({11 apiKey: "my-api-key",12 plan: "tree",13 allocations: [14 { asset: "BTC", pct: 60 },15 { asset: "ETH", pct: 40 },16 ],17 investThreshold: 5,18})1920// Change configuration at runtime21buff.setPlan("forest")22buff.setInvestAsset("ETH")23buff.setAllocations([24 { asset: "BTC", pct: 50 },25 { asset: "ETH", pct: 30 },26 { asset: "SOL", pct: 20 },27])28buff.setThreshold(10)Note
The constructor is synchronous. Wallet derivation is a separate async step via buff.deriveWallet(signature). No signMessage callback is needed — auth is handled via API key or wallet signature headers.