Buy with an AI agent in 5 minutes
What you'll build: a Node.js script that uses Vercel AI's SDK + the Boson GOAT plugin to autonomously buy a test offer on Base Sepolia.
Time: 5 minutes. Stack: Node.js 20+, Vercel AI SDK, GOAT, viem. Network: Base Sepolia testnet (configId: "staging-84532-0").
1. Get a funded testnet wallet
# Generate a new private key, or use an existing one.
node -e "console.log(require('viem/accounts').generatePrivateKey())"Fund it with Base Sepolia ETH from any public faucet (e.g. coinbase.com/faucets).
2. Set up the project
mkdir boson-agent-buyer && cd boson-agent-buyer
pnpm init
pnpm add ai @ai-sdk/anthropic \
@bosonprotocol/agentic-commerce \
@goat-sdk/adapter-vercel-ai \
@goat-sdk/wallet-viem \
viemSet two env vars:
export ANTHROPIC_API_KEY="sk-ant-..."
export PRIVATE_KEY="0x..."3. The script
// agent.ts
import { generateText } from "ai"
import { anthropic } from "@ai-sdk/anthropic"
import { bosonProtocolPlugin } from "@bosonprotocol/agentic-commerce"
import { getOnChainTools } from "@goat-sdk/adapter-vercel-ai"
import { viem } from "@goat-sdk/wallet-viem"
import { createWalletClient, http } from "viem"
import { baseSepolia } from "viem/chains"
import { privateKeyToAccount } from "viem/accounts"
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
const walletClient = createWalletClient({
account,
chain: baseSepolia,
transport: http(),
})
const tools = await getOnChainTools({
wallet: viem(walletClient),
plugins: [
bosonProtocolPlugin({
url: "https://mcp-staging.bosonprotocol.io/mcp",
}),
],
})
const result = await generateText({
model: anthropic("claude-sonnet-4-6"),
tools,
maxSteps: 12,
system: `
You are a Boson Protocol buyer agent on Base Sepolia (configId staging-84532-0).
Find an available test offer with a low price, commit to it, and report the exchangeId.
Do not redeem; just commit.
`,
prompt: "Find and commit to one test offer.",
})
console.log(result.text)Run it:
pnpm tsx agent.tsWhat you should see
The agent will:
- Call
get_offersto find available offers. - Pick one, call
get_supported_tokensto confirm the payment token. - If it's an ERC-20 offer, call
approve_exchange_token. - Call
commit_to_offer, receive the unsigned tx, sign locally, broadcast. - Report the new
exchangeId.
Expected output:
Found offer 123 at 0.001 USDC. Approving USDC… approved. Committing… committed.
Your new exchange: 456.What just happened
- The GOAT plugin pulled all 56 MCP tools from the hosted server and registered them with the model.
- Every state-changing tool returned an unsigned transaction; the wallet you passed in signed and broadcast each one.
- The model orchestrated the calls — choosing the offer, approving the token, committing — without you writing flow logic.
Common gotchas
- No offers found. The staging environment may be empty. Create your own with Quickstart → Build a marketplace first.
InvalidExchangeStateon commit. The offer was voided or sold out between query and commit. Retry; see Build for AI agents → Idempotency & retry.- Subgraph lag. If you immediately try to read the new exchange you may get nothing for 1–3 blocks. See Concepts → Eventing & indexing.
Next
- Build for AI agents → Overview — patterns for production agents.
- Build for AI agents → The 3-step signing pattern — what's happening under the hood.
- Reference → MCP tools — every tool's schema.