Skip to content

masem-at/paywatcher-agentkit-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PayWatcher × AgentKit Example

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.

What This Does

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.

Quick Start

Prerequisites

  • Node.js 18+
  • A wallet with Base Sepolia testnet USDC

1. Clone & Install

git clone https://github.com/masem-at/paywatcher-agentkit-example.git
cd paywatcher-agentkit-example
npm install

2. Configure

cp .env.example .env

Edit .env and add your private key:

EVM_PRIVATE_KEY=0xYOUR_BASE_SEPOLIA_PRIVATE_KEY

3. Fund Your Wallet

Get testnet USDC on Base Sepolia:

  1. Get Base Sepolia ETH from the Coinbase Faucet
  2. Get testnet USDC from the Circle Faucet (select Base Sepolia)

4. Run

# 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

Available PayWatcher MCP 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 Get payment details by ID $0.05
list_verifications List recent verification results $0.05

How x402 Works

x402 is an HTTP-based payment protocol by Coinbase. Instead of API keys, your agent pays per request:

  1. Agent calls MCP tool → PayWatcher returns HTTP 402 Payment Required
  2. x402 client reads payment requirements → amount, asset, network, recipient
  3. Agent sends USDC on-chain → $0.05 on Base Sepolia (automatic)
  4. Agent retries with payment proofX-PAYMENT header
  5. PayWatcher verifies payment → executes tool → returns result

The @x402/mcp package handles steps 2–5 automatically.

Project Structure

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

Integration with Coinbase AgentKit

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_payment

See AgentKit MCP docs for full framework integration (LangChain, Vercel AI SDK).

Production / Mainnet

To run against Base Mainnet instead of Sepolia:

  1. Change the network in src/client.ts:

    const BASE_MAINNET_NETWORK = "eip155:8453";
    // ...
    schemes: [{ network: BASE_MAINNET_NETWORK, client: new ExactEvmScheme(signer) }],
  2. 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...",
    });
  3. Fund your wallet with real USDC on Base.

Note: Each mainnet tool call costs $0.05 real USDC.

Links

License

MIT

About

Example: Coinbase AgentKit + PayWatcher MCP for x402 USDC payment verification on Base

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors