API

Buff.init()

Initialize the SDK — derives the user's Buff wallet and connects to the network.

Signature

types.ts
typescript
1static async init(options: BuffInitOptions): Promise<Buff>

Parameters

OptionTypeDefaultDescription
platformIdstringrequiredYour platform ID (provided by Buff)
signMessage(msg: Uint8Array) => Promise<Uint8Array>requiredWallet adapter sign function
network'mainnet-beta' | 'devnet''mainnet-beta'Solana network
rpcUrlstringautoCustom RPC endpoint (auto-selected by network)
plan'seed' | 'sprout' | 'tree' | 'forest''sprout'Round-up plan tier
roundToUsdnumberCustom round-up increment (overrides plan)
roundUpCeilingnumber1.00Max round-up per tx in USD
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%)
storageBuffStorageautoCustom persistence adapter
priceCacheTtlMsnumber30000Price cache duration in ms

Returns

A Promise that resolves to a Buff instance. The user will be prompted to sign a message during initialization to derive their Buff wallet.

Example

init.ts
typescript
1import { Buff } from "@buff/sdk"
2
3// Single asset — 100% BTC
4const buff = await Buff.init({
5 platformId: "my-dex",
6 signMessage: (msg) => wallet.signMessage(msg),
7 investInto: "BTC",
8})
9
10// Multi-asset portfolio split
11const buff = await Buff.init({
12 platformId: "my-dex",
13 signMessage: (msg) => wallet.signMessage(msg),
14 plan: "tree",
15 allocations: [
16 { asset: "BTC", pct: 60 },
17 { asset: "ETH", pct: 40 },
18 ],
19 investThreshold: 5,
20})
21
22// Change allocation at runtime
23buff.setAllocations([
24 { asset: "BTC", pct: 50 },
25 { asset: "ETH", pct: 30 },
26 { asset: "SOL", pct: 20 },
27])
28console.log(buff.getAllocations())
29// [{asset:"BTC",pct:50},{asset:"ETH",pct:30},{asset:"SOL",pct:20}]
Note
The user only signs once per session. The signature deterministically produces the same Buff wallet every time — no storage needed.