Upgrading to 1.0
1.0 adopts the x402 v2 specification, its HTTP transport and the Canton exact scheme. Most of the changes are breaking because the wire format is the specs' now: a 0.x payer cannot pay a 1.0 merchant, and a 0.x merchant cannot quote for a 1.0 payer.
Before you start
- Upgrade both sides together. Move the merchant and the payers that call it to 1.0 at the same time, against a facilitator that speaks x402 v2 (every network does).
- Node 22.2 or later for every package.
- Every
payToparty needs a liveTransferPreapproval. A payment that would not land directly is refused (invalid_exact_canton_preapproval_missing).
Merchants: @chainsafe/x402-express
Configure ways to pay, not Canton details. Each entry in accepts names an instrument by id and an amount in atomic units (10 decimals for every instrument, so 0.05 CC is "500000000"). The registry admin, the synchronizer and the fee payer come from the facilitator's /v2/supported, and can no longer be set.
ts
// 0.2.0
paymentRequired({
facilitator,
requirements: {
payTo,
network: "canton:1220…",
asset: { instrumentId: { id: "Amulet", admin: "DSO::1220…" } },
amount: "0.05",
nonce: (req) => newOrder(req),
},
});
// 1.0.0
paymentRequired({
facilitator,
requirements: {
payTo,
memo: (req) => newOrder(req),
accepts: [{ asset: "Amulet", amount: "500000000" }], // 0.05 CC
},
});networkis optional. Leave it out and it is discovered from/v2/supported. Named, it is acanton:<name>such ascanton:mainnet, no longer thecanton:1220…hash.- Removed options:
assetas an object,additionalAccepts,validForSecondsandnonce. Usememofor an order reference, but it is not a drop-in fornonce: the middleware doesn't check that amemois one you issued, and nothing makes it single-use. If you reconcile orders on it, check it inpreSettle. - Headers: the 402 carries
PAYMENT-REQUIRED, the payment arrives inPAYMENT-SIGNATURE(X-PAYMENTis still read), and the settle answer goes back inPAYMENT-RESPONSE, which replacesX-PAYMENT-RESPONSE. - CORS: expose
PAYMENT-REQUIREDandPAYMENT-RESPONSE, and allowPAYMENT-SIGNATURE. - Header size: the server and every proxy in front of it must accept a header of at least 16 KiB; see Accept payments.
- A pending settlement is never re-challenged, so a payer retries the same payment instead of paying twice.
- New: the
preSettleandonQuoteErrorhooks, theexecuteBeforeSecondsandmaxTimeoutSecondsoptions, andSchemeAdapterfor gating a route on another scheme.
Payers: @chainsafe/x402-server-sdk
- No public key.
CantonPartyKeyis{ partyId, privateKey }; droppublicKey. The facilitator reads the party's key from the ledger. - Headers:
createX402Fetchsends the payment inPAYMENT-SIGNATUREinstead ofX-PAYMENT, and reads the offer from thePAYMENT-REQUIREDheader. - Don't retry a pending payment. A 402 whose
PAYMENT-RESPONSEissettlement_pending(isSettlementPending) may still land. Retrying the request throughcreateX402Fetchsigns a new payment, so the payer could pay twice. - Custom payers:
X402Payer.authorizereceives the 402'sresourceas a second argument (PaymentContext).
Calling the facilitator: @chainsafe/x402-client
verify,settleandsupportedsend and return the spec's shapes from@chainsafe/x402-core1.0.settlement_pendingis not a failure. Check it withisSettlementPending, and don't ask for a new payment; see Pending payments.supported()caches its answer forsupportedTtlMs(5 minutes by default);supported({ refresh: true })skips the cache.
Shared types: @chainsafe/x402-core
- Requirements and payloads are the spec's
PaymentRequirementsandPaymentPayload. The scheme isexactoncanton:mainnet,canton:testnet,canton:devnetorcanton:localnet, and the payload names the requirements it was built against inaccepted. - Error codes are the spec's, with the cause in
extensions.detail. Codes from 0.x no longer parse; see Error codes. - Verifying a payment yourself takes the payer's keys from the caller:
verify(payload, requirements, { payerPublicKeys }). - Validate with the
is*guards. Most schemas andparse*functions are no longer exported. - New helpers: header codecs for
PAYMENT-REQUIREDandPAYMENT-RESPONSE,selectCantonDeploymentsfor reading/v2/supported, andledgerToAtomic/atomicToLedgerfor amounts. - The
VERSIONexport, which always read0.0.1, is gone from every package.