Skip to main content
The simplest possible x402-paywalled agent. Same echo handler as the basic echo agent, but the message/send method is gated: the server returns HTTP 402 with payment requirements until the caller pays the configured amount ($0.0001 USDC in the example below) on Base Sepolia.

Code

Create echo_agent_behind_paywall.py with the code below, or save it directly from your editor.

How It Works

Handler
  • Same echo logic as the basic echo agent — returns the user’s latest message back
  • No model call, no external dependencies
x402 paywall block
  • execution_cost in the config declares the price and chain
  • amount: $0.0001 charged per request
  • token: USDC
  • network: base-sepolia (testnet — use the Circle faucet for test USDC)
  • pay_to_address: receiving wallet for the payment
  • protected_methods: list of A2A methods that require payment; here only message/send
The 402 response cycle
  • Caller sends message/send with no payment header
  • Server returns HTTP 402 Payment Required with x402 paymentRequirements describing the price, network, token, and payTo address
  • Caller signs an x402 payment (EIP-3009 transfer authorization on Base Sepolia) and resends the request with the X-PAYMENT header
  • Server verifies the signed payment, executes the handler, and returns the JSON-RPC result
Testing it
  • Fund a Base Sepolia wallet with test USDC from the Circle USDC faucet
  • Use an x402-aware client to handle the 402 → sign → retry loop automatically
  • tasks/get is not in protected_methods, so it remains free

Dependencies

Environment Setup

No environment variables required for the server. The caller needs a funded Base Sepolia wallet with test USDC.

Run

Example API Calls

Frontend Setup

Open http://localhost:5173 and try to chat with the echo paywall agent.