AI Agent that verifies on-chain USDC payments using PayWatcher MCP with x402 payment authentication.
Testnet by default — runs on Base Sepolia with testnet USDC. No real funds needed.
Your Agent → calls verify_payment → PayWatcher MCP returns 402
→ x402 auto-pays $0.05 USDC (testnet) → retry → ✅ verification result
Each PayWatcher MCP tool call is authenticated via x402: your agent automatically pays a micro-fee in USDC, and the tool executes. No API keys, no sign-ups — just on-chain payments.
- Node.js 18+
- A wallet with Base Sepolia testnet USDC
git clone https://github.com/masem-at/paywatcher-agentkit-example.git
cd paywatcher-agentkit-example
npm installcp .env.example .envEdit .env and add your private key:
EVM_PRIVATE_KEY=0xYOUR_BASE_SEPOLIA_PRIVATE_KEY
Get testnet USDC on Base Sepolia:
- Get Base Sepolia ETH from the Coinbase Faucet
- Get testnet USDC from the Circle Faucet (select Base Sepolia)
# Full demo: discover tools → create payment intent → show verification flow
npm start
# Or run individual demos:
npm run demo:list-tools # List available MCP tools
npm run demo:verify -- \ # Verify a specific transaction
--tx 0xYOUR_TX_HASH \
--to 0xRECIPIENT \
--amount 1.00| 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 |
Get payment details by ID | $0.05 |
list_verifications |
List recent verification results | $0.05 |
x402 is an HTTP-based payment protocol by Coinbase. Instead of API keys, your agent pays per request:
- Agent calls MCP tool → PayWatcher returns HTTP
402 Payment Required - x402 client reads payment requirements → amount, asset, network, recipient
- Agent sends USDC on-chain → $0.05 on Base Sepolia (automatic)
- Agent retries with payment proof →
X-PAYMENTheader - PayWatcher verifies payment → executes tool → returns result
The @x402/mcp package handles steps 2–5 automatically.
src/
├── client.ts # x402 MCP client setup (wallet, transport, auto-payment)
├── index.ts # Full demo: discover → create → verify
├── list-tools.ts # Discover available MCP tools
└── verify-payment.ts # Verify a specific transaction via CLI args
This example uses @x402/mcp directly for the PayWatcher connection. To integrate with a full AgentKit agent:
import { AgentKit } from "@coinbase/agentkit";
import { createx402MCPClient } from "@x402/mcp";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
// AgentKit for on-chain actions (transfers, swaps, etc.)
const agentKit = await AgentKit.from({
cdpApiKeyName: process.env.CDP_API_KEY_NAME,
cdpApiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
});
// PayWatcher MCP for 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_paymentSee AgentKit MCP docs for full framework integration (LangChain, Vercel AI SDK).
To run against Base Mainnet instead of Sepolia:
-
Change the network in
src/client.ts:const BASE_MAINNET_NETWORK = "eip155:8453"; // ... schemes: [{ network: BASE_MAINNET_NETWORK, client: new ExactEvmScheme(signer) }],
-
Use
"base"instead of"base-sepolia"in tool calls:await client.callTool("verify_payment", { tx_hash: "0x...", network: "base", // ← mainnet amount: "49.99", to: "0x...", });
-
Fund your wallet with real USDC on Base.
Note: Each mainnet tool call costs $0.05 real USDC.
MIT