Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Buy with an AI agent in 5 minutes · Boson Protocol
Skip to content

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 \
        viem

Set 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.ts

What you should see

The agent will:

  1. Call get_offers to find available offers.
  2. Pick one, call get_supported_tokens to confirm the payment token.
  3. If it's an ERC-20 offer, call approve_exchange_token.
  4. Call commit_to_offer, receive the unsigned tx, sign locally, broadcast.
  5. 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

Next