@three-ws/x402-modal
A drop-in payment modal for any x402 paid endpoint.
One <script> tag turns an HTTP 402 Payment Required into a polished checkout:
discover the challenge, connect a wallet (Phantom on Solana, MetaMask / any EVM
wallet via EIP-3009), sign, settle, and show a receipt — in vanilla JS, with no
bundler and no framework.

Install · Quickstart · How it works · API · Configuration · Frameworks · Wallets · FAQ
What & why
x402 revives HTTP 402 Payment Required as a real payment
rail: a server answers a request with a 402 whose body lists what it
accepts (asset · amount · network · pay-to), the client pays, and re-sends the
request with an X-PAYMENT header. It is built for pay-per-call APIs, agent
economies, and content paywalls — but every merchant ends up rebuilding the same
fiddly client: parse the challenge, connect a wallet, sign the right thing for
the right chain, retry, settle, and show a receipt.
This package is that client, done once and done well. Point it at a 402
endpoint and it renders the entire flow.
Features
- Zero-config drop-in — one
<script> tag binds every data-x402-endpoint
element on the page. No build step, no framework, no wallet adapter.
- Works against any origin — the
402 → sign → settle flow is
merchant-agnostic. Point it at your endpoint or someone else's.
- Solana + EVM — Phantom on Solana, MetaMask / any injected
window.ethereum
on Base and other EVM chains. USDC by default; arbitrary SPL tokens supported.
- No bundler required — ships a single self-contained IIFE for
<script>
use, plus a side-effect-free ESM build for bundlers.
- Gasless for the payer — EVM uses EIP-3009 signed authorizations; Solana
uses a facilitator fee-payer. The buyer never needs native gas.
- Spending caps — per-wallet
localStorage caps by call / hour / day, so an
autonomous agent can't overspend.
- Zero runtime dependencies — the two optional wallet libraries are loaded
on demand from a CDN, only when that wallet path actually runs.
- Every state designed — discover, connect, sign, settle, retry, error, and
receipt all render as live rows with light/dark theming.
The EVM/Base path is 100% client-side. The Solana path needs one small
backend helper (see The backend).
Install
npm (bundlers / frameworks)
npm i @three-ws/x402-modal
import { pay, configure } from '@three-ws/x402-modal'; // ESM, no side effects
CDN <script> (no install, no bundler)
The /global build auto-binds [data-x402-endpoint] elements and exposes
window.X402. Pick a CDN:
<!-- unpkg -->
<script type="module" src="https://unpkg.com/@three-ws/x402-modal/global"></script>
<!-- jsDelivr -->
<script type="module" src="https://cdn.jsdelivr.net/npm/@three-ws/x402-modal/global"></script>
Pin a version for production, e.g.
https://unpkg.com/@three-ws/[email protected]/global.
The CDN bundle is a single self-contained file (~12 kB gzipped). No npm, no
build step.
Quickstart
The smallest possible page that pops the modal and settles a 402. Save it as
index.html, replace the endpoint with your own x402 route, and open it:
<!doctype html>
<html lang="en">
<head><meta charset="utf-8" /><title>x402 checkout</title></head>
<body>
<button
data-x402-endpoint="https://api.example.com/paid/summarize"
data-x402-method="POST"
data-x402-body='{"text":"hello world"}'
data-x402-merchant="Acme"
data-x402-action="Summarize">
Pay & summarize
</button>
<pre id="out"></pre>
<script type="module" src="https://unpkg.com/@three-ws/x402-modal/global"></script>
<script type="module">
const btn = document.querySelector('button');
btn.addEventListener('x402:result', (e) => {
document.getElementById('out').textContent =
JSON.stringify(e.detail.result, null, 2);
});
btn.addEventListener('x402:error', (e) => {
document.getElementById('out').textContent = 'Error: ' + e.detail.error;
});
</script>
</body>
</html>