Templatesx402 Monetization

x402 Monetization

An MCP server with x402 payment middleware for USDC micropayments

x402 Monetization preview

Monetize MCP tools with x402 using USDC micropayments on Base.

Features

  • x402 payment middleware for per-tool pricing
  • Free and paid tools in the same server
  • Custom price overrides per tool
  • USDC payments on Base (Sepolia for testing, mainnet for production)
  • Example tools: greet (paid, $0.01), hash-string (paid, $0.05), random-number (free)

Getting Started

Prerequisites

You need a wallet address to receive USDC payments.

1. Create the project

2. Environment setup

Edit .env with your wallet address:

3. Install & run

How It Works

The middleware is configured in src/middleware.ts with default pricing:

  • Default price: 0.01 USDC per tool call
  • Currency: USDC
  • Network: base-sepolia (switch to base for production)
  • Facilitator: https://x402.org/facilitator

Making Tools Paid

Wrap tools with paid() from @xmcp-dev/x402:

Tools without the paid() wrapper are free.

Deploy

For production, update your middleware to use base instead of base-sepolia.

Learn More

Other templates

One framework to rule them all