API

buff.getPortfolio()

Read all token balances and USD values from the Buff wallet.

Signature

types.ts
typescript
1async getPortfolio(): Promise<Portfolio>
2
3interface Portfolio {
4 walletAddress: string
5 balances: TokenBalance[]
6 totalUsd: number // Total invested assets value
7 pendingSol: number // SOL waiting for threshold
8 pendingUsd: number // In USD
9 solPriceUsd: number // Current SOL price
10}
11
12interface TokenBalance {
13 asset: SupportedAsset
14 mint: string
15 balance: string // Human-readable amount
16 decimals: number
17 usdValue: number
18}

Example

portfolio.ts
typescript
1const portfolio = await buff.getPortfolio()
2
3console.log("Wallet:", portfolio.walletAddress)
4console.log("Total invested:", "$" + portfolio.totalUsd.toFixed(2))
5console.log("Pending SOL:", portfolio.pendingSol.toFixed(6))
6console.log("Pending USD:", "$" + portfolio.pendingUsd.toFixed(2))
7
8for (const balance of portfolio.balances) {
9 console.log(balance.asset + ":", balance.balance, "($" + balance.usdValue.toFixed(2) + ")")
10}
11// BTC: 0.00068 ($48.20)
12// ETH: 0.015 ($31.50)

Other Methods

methods.ts
typescript
1// Get the Buff wallet address
2buff.getWalletAddress()
3// "E71R6Ph2sS4eYJVSNLacorUtSDNK1rUixVswgFD5hCY3"
4
5// Export private key (for Phantom import)
6const key = buff.exportKey()
7// Uint8Array(64)
8
9// Get lifetime stats
10const stats = buff.getStats()
11// { totalRoundUps: 142, totalInvestedUsd: 48.20, ... }
12
13// Preview fees without wrapping
14const preview = await buff.previewFees(27.63)
15// { roundUpUsd: 0.37, userInvestmentUsd: 0.3672, ... }
Note
Portfolio values are fetched in real-time from the Solana blockchain with live USD prices from CoinGecko. Prices are cached for 30 seconds.