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
| Option | Type | Default | Description |
|---|---|---|---|
| platformId | string | required | Your platform ID (provided by Buff) |
| signMessage | (msg: Uint8Array) => Promise<Uint8Array> | required | Wallet adapter sign function |
| network | 'mainnet-beta' | 'devnet' | 'mainnet-beta' | Solana network |
| rpcUrl | string | auto | Custom RPC endpoint (auto-selected by network) |
| plan | 'seed' | 'sprout' | 'tree' | 'forest' | 'sprout' | Round-up plan tier |
| roundToUsd | number | — | Custom round-up increment (overrides plan) |
| roundUpCeiling | number | 1.00 | Max round-up per tx in USD |
| 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%) |
| storage | BuffStorage | auto | Custom persistence adapter |
| priceCacheTtlMs | number | 30000 | Price 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"23// Single asset — 100% BTC4const buff = await Buff.init({5 platformId: "my-dex",6 signMessage: (msg) => wallet.signMessage(msg),7 investInto: "BTC",8})910// Multi-asset portfolio split11const 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})2122// Change allocation at runtime23buff.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.