# Building x402-Native AI Agents with Coinbase AgentKit + PayWatcher

*How to build an AI agent that sends and verifies USDC payments autonomously — no API keys, no custodians, no manual steps.*

By [PayWatcher](https://paragraph.com/@paywatcher) · 2026-04-15

agentkit, x402, base, mcp, usdc, ai-agents, stablecoins, building-in-public

---

**The problem with AI agent payments**

Most AI agents today that interact with money do so through centralized APIs — Stripe, PayPal, or bank integrations. That works for fiat. But for on-chain stablecoin payments, it creates a fundamental mismatch: you're using a custodial, permissioned layer to interact with a permissionless network.

The x402 protocol changes that. Instead of "authenticate with an API key and call an endpoint," x402 says: pay with USDC and get access. HTTP 402 — Payment Required — becomes the authentication mechanism itself.

This article shows how to build an agent that does exactly that: sends USDC payments via Coinbase AgentKit, and verifies them via PayWatcher MCP — fully autonomous, fully on-chain.

* * *

**The stack**

Three components, each with a clear responsibility:

**Coinbase AgentKit** gives your agent on-chain capabilities: a CDP wallet, USDC transfers, token swaps, contract interactions. It's the agent's hands.

**x402** defines the payment protocol. When an agent calls a resource, the server responds with HTTP 402 + a payment descriptor (amount, asset, recipient, network). The agent pays, retries with proof, and gets access. No API key exchange, no account creation.

**PayWatcher MCP** is the verification layer. When a payment happens on-chain, PayWatcher confirms it — checking the tx\_hash, amount, recipient, and network. It exposes this as an MCP tool, so agents can call it directly from their workflow.

Together:

    Agent (AgentKit) → calls verify_payment
    → PayWatcher returns HTTP 402 + payment descriptor
    → AgentKit auto-pays $0.05 USDC on Base
    → Agent retries with X-PAYMENT header
    → PayWatcher verifies → returns { verified: true }

* * *

**The code**

Install dependencies:

bash

    npm install @x402/mcp @x402/evm @modelcontextprotocol/sdk viem dotenv
    npm install @coinbase/agentkit

Create the x402-aware MCP client:

typescript

    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 paywatcher = createx402MCPClient({
      name: "my-agent",
      version: "1.0.0",
      schemes: [
        { network: "eip155:84532", client: new ExactEvmScheme(signer) },
      ],
      autoPayment: true,
    })
    
    const transport = new StreamableHTTPClientTransport(
      new URL("https://api.paywatcher.dev/mcp")
    )
    await paywatcher.connect(transport)

Verify a payment:

typescript

    const result = await paywatcher.callTool("verify_payment", {
      tx_hash: "0xabc123...",
      network: "base-sepolia",
      amount: "1.00",
      to: "0xRecipientAddress...",
    })
    
    // { verified: true, status: "confirmed" }

That's it. When `callTool` hits the 402, `@x402/mcp` handles the payment automatically — signs the USDC transfer, attaches the proof header, retries. Your code just sees the result.

* * *

**Why this matters**

The traditional API model assumes a human set up an account, got an API key, and configured billing. That works for web apps. It breaks for autonomous agents.

x402 + MCP removes that assumption entirely. An agent can:

1.  Discover available tools via `tools/list`
    
2.  Call a tool
    
3.  Pay automatically if required
    
4.  Get the result
    

No onboarding. No account. No human in the loop.

For payment verification specifically, this creates a new possibility: agents that can trustlessly confirm a payment happened before releasing a resource, executing a contract, or continuing a workflow — all in a single automated loop.

* * *

**Try it**

*   **Docs:** paywatcher.dev/docs/agentkit
    
*   **Example repo:** github.com/masem-at/paywatcher-agentkit-example
    
*   **MCP Server:** api.paywatcher.dev/mcp
    
*   **Testnet:** Base Sepolia (no real funds needed)
    

The example repo runs end-to-end on Base Sepolia with testnet USDC from the Circle faucet. Clone, configure `.env`, run — the full x402 flow works out of the box.

* * *

**What's next**

PayWatcher is building toward a fully x402-native stack: every API endpoint behind x402, no API keys required at all. AgentKit is the first integration — more frameworks coming.

If you're building with AgentKit, x402, or stablecoin payments and want to connect — find me on Farcaster (@paywatcher) or X (@PayWatcher\_dev).

_Mario Semper — masemIT e.U., Austria. Building PayWatcher in public._

---

*Originally published on [PayWatcher](https://paragraph.com/@paywatcher/building-x402-native-ai-agents-with-coinbase-agentkit-paywatcher)*
