API

new Buff()

Create a Buff client instance — configure auth, plan, and investment preferences.

Signature

types.ts
typescript
1new Buff(options: BuffOptions): Buff

Parameters

OptionTypeDefaultDescription
apiKeystringAPI 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
investIntoSupportedAsset'BTC'Single target asset (use allocations for multi-asset)
allocationsAllocation[][{asset:'BTC',pct:100}]Portfolio split — e.g. [{asset:'BTC',pct:60},{asset:'ETH',pct:40}]
investThresholdnumber5USD threshold before swapping
slippageBpsnumber100Slippage 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" })
3
4// Option 2: Wallet signature auth
5const buff = new Buff({ plan: "sprout" })
6const authMsg = await buff.getAuthMessage()
7const signature = await wallet.signMessage(authMsg)
8buff.setWalletAuth(wallet.publicKey.toBase58(), signature)
9
10// Switch API key at runtime
11buff.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"
2
3// Single asset — 100% BTC
4const buff = new Buff({
5 apiKey: "my-api-key",
6 investInto: "BTC",
7})
8
9// Multi-asset portfolio split
10const 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})
19
20// Change configuration at runtime
21buff.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.