What this covers
- Uses the
python/examples/adk-demofroma2a-x402(demo repo) - Client agent (subscriber) generates x402 session tokens
- Merchant server verifies and settles via Nevermined facilitator over REST
- AP2 carries
payment-requiredandpayment-submittedmessages between agents - Real on-chain credit burns on Base Sepolia (sandbox)
Prerequisites
- Nevermined API keys: one for the merchant (
NVM_API_KEY_SERVER), one for the subscriber (NVM_API_KEY_CLIENT) - A credits plan and agent registered in Nevermined (
NVM_CREDITS_PLAN_ID,NVM_AGENT_ID) - Python 3.11+,
uv(for the demo env) - Google GenAI API key (for the AP2/ADK flow)
Configure the demo
From the root ofa2a-x402:
- Client Agent (subscriber): Generates x402 session tokens using
payments_py. - Merchant Server (agent): Serves AP2
payment-required, verifies/settles via Nevermined facilitator. - Facilitator: Nevermined service that enforces permissions and burns/orders credits.
- Blockchain: Executes the settlement transactions (Base Sepolia in sandbox).
Run it
- Start the merchant server (facilitator + AP2 handler):
- Start the client agent + web UI:
- In the UI, trigger a purchase (e.g., “buy a laptop”). The flow:
- Merchant replies with AP2
payment-required(plan/agent/amount/network) - Client generates x402 session token via Nevermined (
payments_py.x402.get_x402_access_token) - Client sends
payment-submittedcarrying the x402 payload + Nevermined extension - Merchant verifies with facilitator → does the work → settles (burns credits)
- Response includes receipt + transaction hash; balance decrements (e.g., 10 → 8)
Message shapes (adapted from the README)
payment-required:- Includes plan_id, agent_id, amount, network, scheme, and any metadata the merchant wants to expose.
payment-submitted:- Carries the x402 payload with
session_keyplus the copied Nevermined extension.
- Carries the x402 payload with
payment-completed:- Contains the facilitator’s verification/settlement result and transaction hash.
Key SDK touchpoints
- Session token generation (subscriber):
- Facilitator verification + settlement (merchant):
When to use this pattern
- You need AP2/A2A messaging but want enforceable on-chain payments
- You want to keep REST facilitators for verification/settlement while agents talk over AP2
- You need a working reference with real settlement (Base Sepolia) that mirrors the library E2E tests