@three-ws/x402-payment-modal
The complete drop-in checkout for any x402 paid endpoint — wallet connect, sign, settle, receipt.
A drop-in payment modal for any x402 paid endpoint. The
browser client is one ES module with zero runtime dependencies; it turns an HTTP
402 Payment Required challenge into a polished checkout: wallet connect (Phantom
/ Solflare / Backpack on Solana, MetaMask / any EVM wallet on Base via EIP-3009),
the 402 → sign → settle flow, optional SIWX re-entry, client-side spending caps,
and a receipt. It ships a server checkout adapter for the Solana rail
(./server, ./server/express, ./server/vercel) and a React wrapper
(./react) — pick only the pieces you need. Vanilla JS, no bundler required.
<script type="module" src="https://unpkg.com/@three-ws/x402-payment-modal"></script>
<button
data-x402-endpoint="https://api.example.com/paid/summarize"
data-x402-method="POST"
data-x402-body='{"text":"hello"}'
data-x402-merchant="Acme"
data-x402-action="Summarize">
Pay & Run
</button>
That's the whole integration. Clicking the button opens the modal, runs the
payment, calls your endpoint with the signed X-PAYMENT header, and fires an
x402:result event with the response.
Why
x402 lets any HTTP endpoint charge a micropayment per call: the server answers an
unpaid request with 402 and a list of accepted payments; the client pays and
retries with an X-PAYMENT header. The protocol is simple — the wallet UX is
not. This package is the missing front end: a single, framework-agnostic modal
that handles wallet detection, chain switching, signing, settlement, errors,
throttle retries, and the receipt, so you ship a paid endpoint in minutes.
- Zero dependencies, zero build. Plain ES module. Drop in a
<script> tag or
import it. The Solana/EVM crypto helpers are loaded lazily from a CDN only
when a payment is actually attempted.
- Solana + EVM. Phantom (Solana) and any injected EVM wallet (Base USDC
via EIP-3009
transferWithAuthorization). The modal picks the right path from
the 402 challenge.
- USDC by default, multi-token if you want it. USDC is the always-on default
on Solana. Optionally offer a second SPL token (the modal ships a built-in
THREE opt-in) and the buyer gets a token picker — each token is recognized on
sight (symbol, decimals). See
Accepting multiple Solana tokens.
- SIWX re-entry. If a wallet already paid for a resource, it can sign back in
instead of paying again. See docs/siwx.md.
- Spending caps. Optional per-call / hourly / daily caps enforced in the
browser. See docs/spending-caps.md.
- Themeable. Light + automatic dark mode, a full
--x402-* design-token
surface, runtime brand-matching, and a header logo. See
docs/theming.md.
- Accessible. Focus trap + restore,
aria-modal, aria-live step
announcements, :focus-visible rings, prefers-reduced-motion, keyboard Esc
to close.
- Server + React adapters in the box. Framework-agnostic Solana checkout
(
./server) with Express and Vercel adapters, and a first-class React wrapper
(./react) — all behind separate export subpaths, all optional.
Which x402 modal do I want?
This package has a lighter sibling, @three-ws/x402-modal.
Both render a drop-in modal; choose by how much you need.
| @three-ws/x402-payment-modal (this) | @three-ws/x402-modal |
|---|
| Goal | Full checkout SDK: client + server + React | Minimal client-only modal |
| Chains | Solana and EVM (Base/Arbitrum/Optimism) | Client modal, EVM-leaning |
| Solana server adapter | ✅ ./server + Express + Vercel | ❌ bring your own |
| React wrapper | ✅ ./react (X402Button, useX402) | ❌ |
| SIWX re-entry | ✅ | — |
| Client spending caps | ✅ per-call / hour / day | — |
| Multi-token picker (USDC + opt-in SPL) | ✅ | — |
| Builder-code (ERC-8021) echo | ✅ | — |
| Footprint | Larger (more surface) | Smaller, fewer knobs |
Rule of thumb: taking real Solana payments, want a React component, or need
caps/SIWX → use this package. Just need a tiny EVM paywall button and nothing
else → the lighter @three-ws/x402-modal is enough.
Package subpaths
Import only what you use — each subpath is independent and its peer deps are
optional.