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 v1.0.0 uses API key authentication — no browser wallet or signMessage callback needed.
Method 1: API Key Authentication
The simplest approach for agents. Create a Buff instance with your API key and configure your plan.
1import { Buff } from "buff-protocol-sdk"23const buff = new Buff({4 apiKey: "your-api-key",5 plan: "sprout",6 investInto: "BTC",7})89// Derive a deterministic wallet from a signature10const wallet = await buff.deriveWallet(agentSignature)11console.log("Agent wallet:", wallet.pubkey)Method 2: Register an Agent
Register your agent with a public key and agent ID. This helps track round-ups by agent in your analytics.
1import { Buff } from "buff-protocol-sdk"23const buff = new Buff({4 apiKey: "your-api-key",5 plan: "sprout",6 investInto: "BTC",7})89// Register agent for tracking and analytics10await buff.registerAgent(agentPubkey, "claude-trading-bot")Method 3: For Claude / GPT Agents
When running inside an AI agent framework, use the API key and register with an agent identifier for analytics.
1import { Buff } from "buff-protocol-sdk"23const buff = new Buff({4 apiKey: process.env.BUFF_API_KEY,5 plan: "sprout",6 investInto: "BTC",7 investThreshold: 5,8})910// Register the agent11await buff.registerAgent(agentPubkey, "claude-trading-bot")1213// Calculate round-up for any spend14const breakdown = await buff.calculateRoundUp(0.50)15console.log("Round-up:", breakdown.roundUpUsd)Funding the Agent Wallet
The agent wallet needs SOL to pay for round-ups and transaction fees. Derive a wallet using buff.deriveWallet() and transfer SOL to the returned address. 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.deriveWallet(signature) to get a deterministic deposit address
Calculate Round-Ups for Non-Transaction Spends
Agents often pay for API calls, compute, or other services that aren't Solana transactions. Use calculateRoundUp() to compute the round-up amount, then use getWrapInstructions() to get the transfer instructions.
1// Calculate round-up for an API call cost2const breakdown = await buff.calculateRoundUp(0.50)3console.log("Round-up:", breakdown.roundUpUsd)45// Get instructions to transfer the round-up amount6const { instructions } = await buff.getWrapInstructions(7 0.50, agentPubkey, buffWalletPubkey8)910// Build and execute swap when threshold is reached11const { ready, transactions } = await buff.buildSwap(buffWalletPubkey)12if (ready) {13 for (const tx of transactions) {14 const signed = signTransaction(tx) // sign with agent keypair15 await buff.executeSwap(Buffer.from(signed).toString("base64"))16 }17}