Skip to main content

Prerequisites

  • A developer account / credentials for x402 (you must obtain these from the x402 provider).
  • A wallet for client-side signing (Phantom, WalletConnect, etc.).
  • Node.js for the backend example or the matching engine (Unity/Unreal) for platform examples.
Our examples use placeholder keys and config. Replace those with your x402 credentials and keep them server-side.

Quick flow (5 steps — same for all platforms)

  1. Create payment session — client calls your backend (POST /create-payment). Backend builds payload and (optionally) calls x402 create API.
  2. Return signable payload — backend returns paymentId + payload to the client.
  3. User signs — client prompts wallet (WalletConnect / MetaMask / mobile wallet) to sign the payload.
  4. Confirm — client sends signature + paymentId to your backend (POST /confirm-payment). Backend verifies signature then calls x402 confirm/finalize.
  5. Finalize + webhook — x402 or your backend sends final status (webhook); update UI, grant item, log txHash.
Note: this is the common x402 flow — Gx402 adds deterministic payload shapes, engine-native patterns, and middleware examples (idempotency, webhook verification, relayer support).

Express server middleware (concept + example)

This is the core middleware pattern we include in templates. Replace X402_* placeholders with credentials from your x402 provider.

server.js (Node + Express — simplified)