Prerequisites
Before you begin, ensure that you’ve:- Completed the seller quickstart or the x402 seller integration.
- Set up a datastore (database, key-value store, or ledger) where you can record payment metadata.
Steps
1
Record settlement metadata
Register an If your attribution scheme relies on a request header the buyer sends
rather than the resource URL, read the header from
onAfterSettle
hook to capture attribution data the moment settlement succeeds. If you
added nanopayments to an existing x402 server
(using x402ResourceServer),
register the equivalent hook on your x402ResourceServer instead. The
payload and result fields are the same either way.onProtectedRequest and
thread the value through to onAfterSettle using AsyncLocalStorage or a
per-request context object.2
Look up a payment by nonce
When you need the full transfer record for a single payment, look it up by
nonce and then fetch by ID.
3
Reconcile a date range
Using the Transfers with no matching local record are typically test payments or
direct transfers sent outside the x402 flow.
GatewayClient from Step 2, search by recipient address and
date range, paginate through the results, and match each transfer to a
local record by nonce.4
Handle settlement outcomes
Before treating a payment as final, check Transfer status definitions are in the
SDK reference.
transfer.status. Wait for
confirmed before crediting the payer for accounting purposes and
completed before initiating any dependent onchain operation. Transfers
that end in failed were never charged. Do not fulfill the resource in
that case.Register an onSettleFailure hook so failed settlements are recorded when
they happen rather than surfaced later during reconciliation.