402 Payment Required. Dash implements the server side of x402 v2, scheme exact: it names a price, hands the signed payment to a facilitator, and runs the route once the facilitator confirms. Dash holds no payment keys and does no chain work. The extension pays as well, from a wallet of its own (see "Wallet"): for the person, not for agents.import { createPaywall, createRPCRoute } from "@dash/server";
const paywall = createPaywall({
facilitator: "https://x402.org/facilitator", // testnet only; use a production one for mainnet
network: "eip155:84532", // CAIP-2 id
asset: "0x…", // the token contract
extra: { name: "USDC", version: "2" }, // the token's EIP-712 name() and version()
payTo: "0x…", // your wallet
});
// src/app/api/rpc/report.ts
export const POST = paywall.charge("0.001", createRPCRoute(schema, handler));charge(price, handler) returns a handler of the same kind, so it wraps an RPC route (its schema is kept), a plain route, or a handler that takes (req, payment). payment is { payer, amount, asset, network }, known only after verification.price is a decimal in whole units ("0.001", converted with decimals, default 6). It can also be { price | amount, description, mimeType } (amount in atomic units), or a function of the request, for a price that depends on what is asked for.Nothing is built in for tokens or networks. asset, network and extra are yours to set from the network's published values, because a wrong token address sends money to the wrong place. Read name() and version() from the token contract, and the facilitator's GET /supported lists what it handles.PAYMENT-SIGNATURE header: 402 with the requirements in a PAYMENT-REQUIRED header (base64 JSON, also repeated as the body).PAYMENT-SIGNATURE (base64 JSON PaymentPayload).accepted must equal our own requirements (scheme, network, amount, asset, recipient), or it is refused with invalid_payment_requirements. The facilitator is always sent our requirements, never the caller's.POST {facilitator}/verify; if invalid, 402 with the facilitator's reason.POST {facilitator}/settle; on success the response gets a PAYMENT-RESPONSE header (base64 JSON with the transaction), on failure the route's answer is withheld and the caller gets 402.settle: "before" swaps steps 5 and 6: the route never runs unpaid, and a failure afterwards is not refunded. The default after costs the caller nothing when the route fails.A facilitator that cannot be reached is 503; the route does not run. A facilitator that needs authentication takes facilitator: { url, headers(endpoint) }.payment_already_used) without running the route, so one signature does not get several answers. That memory is per process; across several instances the facilitator's settlement is what stops a second spend, and the route may have run on both./verify call to the facilitator. Put the paid routes under rateLimit.PAYMENT-SIGNATURE and exposes PAYMENT-REQUIRED and PAYMENT-RESPONSE. Dash's own web and terminal clients do not pay: they show the 402 as an error.invalid_exact_evm_signature. Not done: a payment made with a real wallet through a real facilitator and chain.exact with one configured token. Agents do not spend from it (see "Agents").Network | Chain | Token contract | EIP-712 name, version |
|---|---|---|---|
| Testnet | Base Sepolia, eip155:84532 | 0x036CbD53842c5426634e7929541eC2318f3dCF7e | USDC, 2 |
| Mainnet (the default) | Base, eip155:8453 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 | USD Coin, 2 |
name and version were read from the contracts, and each contract's DOMAIN_SEPARATOR equals the one computed from these values and our encoding, so a signature made here is for the right token on the right chain.The Wallet tab shows which network is in use. The Use testnet checkbox is in the Settings tab; ticking it switches at once, unticking goes back to mainnet. Allowances and the 24-hour totals are kept per network, so an allowance set on the testnet never applies on mainnet, and the log shows only the network in use. The address is the same on both. A payment that is waiting keeps the network it was asked on. There is no build option: every build has the wallet, and the wallet code is only in the background worker's bundle.secret = HKDF-SHA256(master, info = "dash-wallet-v1 evm " ‖ counter), taking the first counter (from 0) whose 32 bytes are a valid secp256k1 scalar. It sits under the same passphrase, passkey and lock as the site keys, and the same 24 words and passphrase recover it. It is not a BIP-44 wallet: loading the phrase into another wallet gives unrelated keys, so funds are reachable only through Dash. The remedy is Private key in the Wallet tab, which shows the key after the same proof as showing the recovery phrase (passphrase or passkey) and hides it again. The address is the last 20 bytes of keccak-256 of the uncompressed public key, with its EIP-55 checksum; it is remembered, so the tab shows it while the identity is locked. There is no balance (that needs a chain call). Treat the wallet as pocket money.exact){ name, version, chainId, verifyingContract }, where chainId comes from the CAIP-2 network, verifyingContract is the configured token, and name and version are the configured values, never the server's.TransferWithAuthorization(address from, address to, uint256 value, uint256 validAfter, uint256 validBefore, bytes32 nonce), with from the wallet, to = payTo, value = amount, validAfter = now − 600 s, validBefore = now + maxTimeoutSeconds, and a random 32-byte nonce.r ‖ s ‖ v with v 27 or 28, low-s.PaymentPayload of the flow above, accepted echoing the chosen requirement.exact, a network or asset other than the one selected (so on the testnet a mainnet price is not paid, and the reverse), an extra.name or extra.version that differs from ours, a zero amount, a recipient that is not an address.resource.url must be on the origin that asked (the browser's own record of the sender). A site cannot make the extension pay for another site's resource.maxTimeoutSeconds above 300 is refused, so an unspent authorization expires soon.payTo, validity, and what was signed on the site in 24 hours. Pay or Cancel, and optionally "Pay without asking here, up to…" with the limits filled in (the payment, and twenty times it per day) and editable. A locked identity asks for the passphrase or passkey on the card, even inside an allowance.402 and nothing happens. When it does need the person, the toolbar button shows a number and nothing is drawn on the page and no window opens, so there is nothing for a page to imitate or cover. Opening the popup shows only the card; the menu comes back once it is decided. The request ends when its tab goes or navigates, or after three minutes. A payment inside the allowance needs no click and no number, which is what an allowance is for.payTo. The allowance and the card bound the loss to what the person allowed there. The allowance is the real control; there is no recipient allow-list.payTo, nonce, and the transaction from PAYMENT-RESPONSE once the page reports it (for display only; the page is not trusted). The last 500 are kept locally and are not part of the backup. The Wallet tab lists the latest 50.boot.js, in the page's own world) wraps fetch. A request to the same origin that is answered 402 with a PAYMENT-REQUIRED header is passed, through the content script, to the background worker; if the worker signs, the request is repeated once with PAYMENT-SIGNATURE. A refusal, or a second 402, leaves the page with what it got. Requests with a streamed body are not repeated. Only the worker holds the key (keys are derived when needed and dropped); the popup asks the worker for the address, the log and the key.@noble/curves and @noble/hashes, both pinned exactly at 2.3.0 with npm provenance. The projects report audits by Trail of Bits (curves, everything, 2.3.0; secp256k1 also in 2023) and Cure53 (hashes, 2022, SHA-3 and Keccak included). Their own documentation says constant time is a goal JavaScript cannot guarantee; the key signs locally in the worker with no remote observer. Both have a single maintainer (noted in dependency-policy.json). Our own code is the EIP-712 encoding. The key and signature code was cross-checked against viem: addresses, digests and signatures are identical for two token domains and values from 0 to the maximum, and a signature recovers to the wallet's address.createPaywall, and a mock facilitator that recovers the signer from the authorization itself (viem): the toolbar button shows a number, nothing is drawn on the page and no popup opens by itself; the popup shows only the card with the site's raw fields, and Pay pays (Cancel refuses; ticking the allowance keeps it and the next payment is silent, with no number; the menu comes back afterwards), and the facilitator verified a signature by the wallet's address and settled once for the right amount to the right recipient within 60 s; the receipt reaches the page and the log; inside an allowance payments are silent; the payment that would pass the daily limit asks; a payment over the per-payment limit asks; a resource on another site, another network and a one-hour authorization are never signed and show no number; outside the allowance with no click, nothing is shown; with the identity locked the card asks for the passphrase, a wrong one leaves the card open and the right one pays; the private key is refused for a wrong passphrase and is the key of the shown address. It starts on mainnet; ticking "Use testnet" switches at once; after that the allowance and log are empty on the other network and a mainnet price is asked, labelled mainnet; a testnet price is not paid while on mainnet even though an allowance exists on the testnet; and the testnet allowance is still there after switching back. Not done: a payment from a real wallet funded on a real chain through a real facilitator (the signature is checked by the mock facilitator and against the token contracts' domain separators, not settled on chain), and a passkey-locked identity approving a payment in the real toolbar popup.upto and batch-settlement (usage-based and batched charges) are not supported; offers list one option.exact is signed. Solana's scheme builds a transaction (blockhash, token accounts) and needs an RPC; it would not need a new library.