Accept payments
This takes a merchant from a fresh account to a live, paid endpoint: link the Canton party that gets paid, create an API key, gate an Express route with @chainsafe/x402-express, and take your first payment. The facilitator does the on-ledger work — you write a few lines of middleware. The facilitator explains what it is; this page is the hands-on part. Building the paying side instead? See Pay for an API.
Before you start
- A Canton party to receive payouts — you link it in step 1, and it becomes your payout party.
- A Node.js + Express server — the API you want to charge for.
- Your facilitator's base URL,
FACILITATOR_URL— the DevNet and MainNet facilitators are listed on Networks. The integration panel on the merchant dashboard's API keys page shows it, with the other values the server below reads, as a.envyou can copy.
Set up your account
Sign in and link your payout party
Sign in to the merchant dashboard with your Canton key. If you signed in another way, link a Canton key on the dashboard's Account page. The key's party is your
payTo: the payer transfers Canton Coin straight to it, and the facilitator holds no balance. A direct transfer needs aTransferPreapprovalon the party — see How you get paid.Create an API key
On the merchant dashboard's API keys page, create a key. It is shown once — copy it now. Your server sends it as
Authorization: Bearerto the facilitator on every verify and settle. The full key is never stored — Your API key is the facilitator credential covers what is kept, rotation, and revocation.
Wire up your server
Install the SDK
Three packages: the Express middleware, the facilitator client it calls, and the shared types and helpers.
bashnpm install @chainsafe/x402-express @chainsafe/x402-client @chainsafe/x402-coreKnow what your facilitator settles (you do not have to configure it)
GET $FACILITATOR_URL/v2/supportedsays what a deployment settles: thenetworkid, and inkinds[].extrathe synchronizer it submits to, the party that relays your payments (feePayer), and the instruments it validates, each with the registry party that admins it.The middleware reads this for you. Name the instrument by id —
asset: "Amulet"— and the rest comes from the facilitator: the synchronizer, the party that relays your payments, and the registry party they are validated against. These are the facilitator's own facts, so you cannot configure them: a wrong one would only fail at verify, after the payer had signed. It is fetched once and cached (seesupportedTtlMsonFacilitatorClient), not per request.assetitself is required on every way to pay:amountis atomic units of something, so each entry says what.networkis optional: leave it out and it is discovered, or name it to choose. If the facilitator settles that instrument on more than one network, naming one is required rather than guessed. Every field is described on Facilitator APIs.Gate a route
Point a
FacilitatorClientat the facilitator with your API key, then wrap the route you want to charge for withpaymentRequired(). Withsettle: truethe middleware verifies and settles in one shot; a paid, verified request then reaches your handler with the payer onreq.x402.Raise your server's max header size
The
PAYMENT-SIGNATUREheader 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 create the server with a largermaxHeaderSize, or a paid retry with a few more headers dies with431 Request Header Fields Too Largebefore your handler ever runs. A proxy in front needs room for it too: nginx's defaultlarge_client_header_buffers 4 8krefuses any single header over 8 KiB.
Putting it together
import http from "node:http";
import express from "express";
import { FacilitatorClient } from "@chainsafe/x402-client";
import { paymentRequired } from "@chainsafe/x402-express";
// The .env the dashboard's integration panel gives you (API keys page).
// The network is NOT in here, and neither is the instrument's registry party:
// the middleware reads them from the facilitator's own GET /v2/supported, so
// there is no copy of them to keep true when a deployment changes. The
// instrument itself is named below, since a price means nothing without it.
const PAY_TO = process.env.MERCHANT_PARTY!; // your payout party (step 1)
const API_KEY = process.env.FACILITATOR_API_KEY!; // your API key (step 2)
const facilitator = new FacilitatorClient(process.env.FACILITATOR_URL!, { apiKey: API_KEY });
const app = express();
// Gate one route behind a 0.05 CC payment, settled on Canton.
app.use(
"/paid",
paymentRequired({
facilitator,
settle: true,
requirements: {
// Only what is the merchant's own business: who is paid, for what...
payTo: PAY_TO,
description: "Access to /paid",
// ...and the ways to pay for it. One here; add an entry per instrument.
accepts: [{ amount: "500000000", asset: "Amulet" }], // 1 CC = 1e10, so 0.05 CC
},
}),
);
app.get("/paid", (req, res) => {
// Paid + verified — req.x402 carries the payer and the settle result.
res.json({ ok: true, payer: req.x402!.payer });
});
// Raise maxHeaderSize (step 6): PAYMENT-SIGNATURE is about 10 KB, much of Node's 16 KB
// default for all headers, so a paid retry can 431 before the handler runs.
http
.createServer({ maxHeaderSize: 4 * 1024 * 1024 }, app)
.listen(3000, () => console.log("listening on :3000"));Its settings are the integration panel's .env: FACILITATOR_URL, FACILITATOR_API_KEY and MERCHANT_PARTY. NETWORK_ID and AMULET_ADMIN are not among them — those come from /v2/supported, as step 4 describes.
Take your first payment
Pay the route and confirm it
Call your gated route from a payer wired up with the payer SDK (Pay for an API shows how). Once it settles, the payment shows up on the merchant dashboard's Settlements page with its on-ledger update id.
Next
Express middleware covers every option: several ways to pay, memos and preSettle, and what each request goes through. The payment flow walks a request end to end.