The payment flow
A paid request end to end under exact on Canton — from the 402 your route returns to the on-ledger update id it settles with. This is what runs underneath the route you gated in Accept payments, and The facilitator covers steps 5 and 6 in depth. You write almost none of it: the merchant side (steps 1, 5 and 6) is handled via @chainsafe/x402-express, and the payer side (steps 2–4) via the payer's own SDK, @chainsafe/x402-server-sdk. You configure two things yourself: your route's price and terms in the x402-express middleware (step 1), and the max header size on your resource server (step 4).
Client hits a gated route (402)
Your route answers
402 Payment Requiredwith the spec'sPaymentRequired,{ x402Version: 2, resource, accepts: [...] }, base64-encoded in thePAYMENT-REQUIREDheader and as the body.resourcenames what is being paid for: the request URL and the route's description. Eachacceptsentry carriesscheme,network,amount,asset,extra.assetTransferMethod,extra.synchronizerId,extra.feePayer(the facilitator's own party),extra.instrumentId,extra.executeBeforeSeconds(120 by default, and optionally anextra.memo),payTo(your Canton party) and amaxTimeoutSeconds(60 by default).Payer builds the transfer
The payer queries its Amulet holdings and fetches a
TransferFactoryfrom the Splice Token Standard registry for the asset — the validator scan-proxy for Amulet.Prepare and sign
The payer calls Canton's
interactive-submission/prepareto get the transaction blob and its hash, then Ed25519-signs that hash with its party key. Nothing is executed, and the private key never leaves the payer.Retry with
PAYMENT-SIGNATUREThe payment — the requirements it was built against as
accepted(theaccepts[]entry the payer chose), and the payload:assetTransferMethod,preparedTransaction,preparedTxHash,signature,hashingSchemeVersion— is JSON-encoded, base64'd into aPAYMENT-SIGNATUREheader, and the request is retried. That header carries the prepared transaction, gzipped, with its disclosed contracts. The middleware also reads a payment of this shape sent underX-PAYMENT, the name this SDK used before.Merchant verifies, then settles
Your middleware re-checks the payment against your own terms — scheme, network,
payTo, asset,maxTimeoutSeconds, and that it is neither underpriced nor expired — using the exact requirements the payment was built against, itsaccepted, which the facilitator then holds the signed transfer to, so a payment built for other terms can't pass. It then POSTs{ x402Version, paymentPayload, paymentRequirements }to/v2/verifyand, withsettle: true(the default isfalse: verify only), to/v2/settle, with your API key. A payment that fails your terms or the facilitator's verify gets a fresh challenge (a new402) instead of being settled.Facilitator executes on Canton
/v2/settlere-runs every verify check, then calls Canton'sexecuteAndWaitForTransactionwith the payer-signed blob. On success it returns the update id astransaction. The middleware puts the whole settle answer on your response asPAYMENT-RESPONSE(base64 JSON), and your handler runs with the verified payer onreq.x402.
Raise your server's max header size
The PAYMENT-SIGNATURE header from step 4 runs to about 10 KB for a typical transfer — much of Node's ~16 KB default, which covers all of a request's headers together — so a Node/Express merchant server should set maxHeaderSize (e.g. --max-http-header-size) or the paid retry dies with 431 Request Header Fields Too Large before your handler ever runs. Step 6 of Accept payments shows where it goes. The scheme spec asks every server and proxy on the way to accept at least 16 KiB for this header. A proxy in front needs it too: nginx's default large_client_header_buffers 4 8k refuses any single header over 8 KiB.