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
Createecho_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
execution_costin the config declares the price and chainamount:$0.0001charged per requesttoken:USDCnetwork:base-sepolia(testnet — use the Circle faucet for test USDC)pay_to_address: receiving wallet for the paymentprotected_methods: list of A2A methods that require payment; here onlymessage/send
- Caller sends
message/sendwith no payment header - Server returns HTTP 402 Payment Required with x402
paymentRequirementsdescribing the price, network, token, andpayToaddress - Caller signs an x402 payment (EIP-3009 transfer authorization on Base Sepolia) and resends the request with the
X-PAYMENTheader - Server verifies the signed payment, executes the handler, and returns the JSON-RPC result
- 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/getis not inprotected_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
Message Send Request (no payment)
Message Send Request (no payment)
402 Payment Required Response
402 Payment Required Response
Message Send Request (with X-PAYMENT header)
Message Send Request (with X-PAYMENT header)
Successful Response (after payment)
Successful Response (after payment)
Task get Request
Task get Request