AgentKit Integration#
Build autonomous AI agents that verify on-chain USDC payments using Coinbase AgentKit and PayWatcher MCP. AgentKit agents can pay for tool calls automatically via x402 — no API key needed.
Why AgentKit + PayWatcher?#
- AgentKit gives AI agents on-chain capabilities: send USDC, swap tokens, deploy contracts
- PayWatcher MCP gives agents payment verification: confirm that USDC arrived at the right address
- x402 ties them together: each MCP tool call is paid with a micro-transaction ($0.05 USDC)
Together, your agent can both send and verify payments — fully autonomous, fully on-chain.
Quick Start#
1. Install#
npm install @x402/mcp @x402/evm @modelcontextprotocol/sdk viem dotenv2. Create the x402 MCP Client#
import { createx402MCPClient } from "@x402/mcp"
import { ExactEvmScheme } from "@x402/evm/exact/client"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { privateKeyToAccount } from "viem/accounts"
const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`)
const client = createx402MCPClient({
name: "my-agent",
version: "1.0.0",
schemes: [
{ network: "eip155:84532", client: new ExactEvmScheme(signer) },
],
autoPayment: true,
onPaymentRequested: async (context) => {
const price = context.paymentRequired.accepts[0]
console.log(`Paying ${price.amount} ${price.asset} for ${context.toolName}`)
return true // approve payment
},
})
const transport = new StreamableHTTPClientTransport(
new URL("https://api.paywatcher.dev/mcp")
)
await client.connect(transport)The createx402MCPClient wraps the standard MCP client. When a tool call returns HTTP 402, it automatically pays $0.05 USDC and retries — your code just sees the result.
3. Call PayWatcher Tools#
// Verify a payment
const result = await client.callTool("verify_payment", {
tx_hash: "0xabc123...",
network: "base-sepolia",
amount: "1.00",
to: "0xRecipientAddress...",
})
// Create a payment intent
const payment = await client.callTool("create_payment", {
amount: "49.99",
currency: "USDC",
network: "base-sepolia",
})Each call triggers the x402 flow automatically:
callTool() → 402 → auto-pay $0.05 USDC → retry → ✅ resultx402 Payment Flow#
Every PayWatcher MCP tool call is authenticated via x402. Here's what happens under the hood:
| Step | What happens |
|---|---|
| 1 | Agent calls verify_payment via MCP |
| 2 | PayWatcher returns HTTP 402 + payment requirements |
| 3 | @x402/mcp reads the requirements (amount, asset, network, recipient) |
| 4 | Agent sends $0.05 USDC on-chain (automatic) |
| 5 | Agent retries with X-PAYMENT header (tx proof) |
| 6 | PayWatcher verifies payment → executes tool → returns result |
With autoPayment: true, steps 2–6 are handled automatically by the @x402/mcp package.
Available Tools#
| Tool | Description | Cost |
|---|---|---|
verify_payment | Verify an on-chain USDC transaction | $0.05 |
create_payment | Create a payment intent with deposit address | $0.05 |
get_payment | Retrieve payment details by ID | $0.05 |
list_verifications | List recent verification results | $0.05 |
See the full MCP Server Reference for parameter details.
Full AgentKit Integration#
To combine PayWatcher MCP with a full AgentKit agent (CDP wallet + AI framework):
import { AgentKit } from "@coinbase/agentkit"
import { createx402MCPClient } from "@x402/mcp"
import { ExactEvmScheme } from "@x402/evm/exact/client"
import { privateKeyToAccount } from "viem/accounts"
// AgentKit: on-chain capabilities (transfers, swaps, contracts)
const agentKit = await AgentKit.from({
cdpApiKeyName: process.env.CDP_API_KEY_NAME,
cdpApiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
})
// PayWatcher MCP: payment verification (via x402)
const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`)
const paywatcher = createx402MCPClient({
name: "my-agent",
version: "1.0.0",
schemes: [
{ network: "eip155:84532", client: new ExactEvmScheme(signer) },
],
autoPayment: true,
})
// Your agent now has:
// - AgentKit tools: send USDC, swap tokens, deploy contracts
// - PayWatcher tools: verify_payment, create_payment, get_paymentAgentKit supports LangChain, Vercel AI SDK, and MCP as AI frameworks. See the AgentKit MCP docs for framework-specific setup.
Testnet Setup#
The example above uses Base Sepolia (testnet) by default. To get started:
- Base Sepolia ETH — Coinbase Faucet
- Testnet USDC — Circle Faucet (select Base Sepolia)
No real funds required. PayWatcher supports Base Sepolia (chain ID 84532) alongside all production networks.
Production / Mainnet#
Switch to Base Mainnet by changing two values:
// Network: eip155:8453 (Base Mainnet)
schemes: [
{ network: "eip155:8453", client: new ExactEvmScheme(signer) },
]
// Tool calls: use "base" instead of "base-sepolia"
await client.callTool("verify_payment", {
tx_hash: "0x...",
network: "base",
amount: "49.99",
to: "0x...",
})Each mainnet tool call costs $0.05 real USDC.
Example Repository#
For a complete, runnable example see:
paywatcher-agentkit-example — Clone, configure, run. Includes tool discovery, payment intent creation, and verification demo on Base Sepolia.
Links#
- MCP Server Reference — Full tool parameter docs
- x402 Quick Start — How x402 payment authentication works
- Supported Networks — All chains and testnets
- AgentKit Docs — Coinbase AgentKit documentation
- x402 Protocol — Open-source x402 specification