Skip to content

x402 server-side middleware: respond to 402 with switchboard-managed payments #16

@abhicris

Description

@abhicris

Why

x402 joined the Linux Foundation on 2026-04-02 with Coinbase, Google, AWS, Microsoft, Stripe, Visa, Mastercard, Circle as founding members and 35M+ transactions on Solana since launch. It's becoming the default agent ↔ HTTP-server payment standard. Switchboard already manages agent wallets, nonces, and gas budgets — it should also be the easiest way for a switchboard-managed agent to respond to an x402 challenge, and (separately) for a service to issue x402 challenges paid out of switchboard escrow.

Scope

Two pieces, behind feature flags:

  1. Client middleware (switchboard.x402.client) — wraps any requests / httpx / fetch call. On a 402, parses PaymentRequirements, picks a matching (scheme, network, asset) we have a wallet for, signs a PaymentPayload, retries with PAYMENT-SIGNATURE header. Honours the gas-budget tracker (PR feat: gas budget tracker with configurable hour/day limits (closes #5) #14) — refuses to pay if the wallet is paused.
  2. Server middleware (switchboard.x402.server) — Flask + FastAPI + Express adapters that:
    • return 402 + PaymentRequirements when no payment header is present;
    • verify the inbound PaymentPayload (locally for off-chain schemes, on-chain for the exact scheme);
    • emit a receipt + nonce so retries are idempotent.

Deliverables

  • switchboard/x402/client.py + switchboard/x402/server.py.
  • Sample app under examples/x402_premium_endpoint/ showing a paid /inference endpoint and a switchboard-driven client.
  • pytest fixtures with a stubbed facilitator (no live RPC needed in CI).
  • Schema-conformance tests against the x402 spec.
  • Docs section referencing the /switchboard/ dashboard's protocol map.

Non-goals

  • Multi-network selection logic — start with USDC on Base only.
  • Fiat / SPT integration (that's MPP territory; tracked separately).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions