Agent Integration
Run Buff in headless mode for AI agents, bots, and server-side scripts — no browser wallet required.
Why Headless Mode?
Browser wallets like Phantom work great for humans, but AI agents and automated systems need a different approach. Buff supports three initialization methods that skip the browser wallet entirely.
Method 1: Direct Keypair
Generate or load a Solana keypair and pass it directly. This is the simplest approach for agents that manage their own keys.
1import { Buff } from "@buff/sdk"2import { Keypair } from "@solana/web3.js"34// Method 1: Direct keypair5const keypair = Keypair.generate()6const buff = await Buff.init({7 agentKeypair: keypair,8 platformId: "my-agent",9 plan: "sprout",10 investInto: "BTC",11})Method 2: From Seed (Deterministic)
Derive a keypair from a hex-encoded 32-byte seed. The same seed always produces the same wallet, making it easy to recover or share state across restarts.
1import { Buff } from "@buff/sdk"23// Method 2: From seed (deterministic)4const buff = await Buff.init({5 agentSeed: "hex-encoded-32-byte-seed",6 platformId: "my-agent",7})Method 3: For Claude / GPT Agents
When running inside an AI agent framework, pass the keypair along with an agent identifier and source tag. This helps track round-ups by agent in your analytics.
1import { Buff } from "@buff/sdk"23// Method 3: For Claude/GPT agents4const buff = await Buff.init({5 agentKeypair: agentWallet,6 agentId: "claude-trading-bot",7 source: "agent",8})Funding the Agent Wallet
The agent wallet needs SOL to pay for round-ups and transaction fees. Transfer SOL to the wallet address returned by buff.getWalletAddress(). On devnet, you can use the Solana faucet. On mainnet, transfer from an existing wallet or fund via an exchange.
- –Minimum balance: ~0.01 SOL covers several hundred round-ups
- –The agent wallet is a standard Solana keypair — fund it like any other wallet
- –Use buff.getWalletAddress() to get the deposit address
Using wrapAmount() for Non-Transaction Round-Ups
Agents often pay for API calls, compute, or other services that aren't Solana transactions. Use wrapAmount() to record a round-up without wrapping an on-chain transaction.
1// Record a round-up (agent pays for API, records the round-up)2const { breakdown } = await buff.wrapAmount({3 txValueUsd: 0.50, // cost of API call4 source: "agent",5})67console.log("Round-up:", breakdown.roundUpUsd)8// Accumulated in the Buff wallet, auto-invests at threshold