Skip to main content
As a seller accepting nanopayments, Gateway settles them in batches, so a completed request on your server confirms only that the payment was accepted, not that it settled. Reconcile payments to attribute each settled nanopayment to the request that triggered it, look up a payment’s full state, or produce ledger exports from Gateway’s transfer history.

Prerequisites

Before you begin, ensure that you’ve:

Steps

1

Record settlement metadata

Register an 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.
If your attribution scheme relies on a request header the buyer sends rather than the resource URL, read the header from 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 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.
Transfers with no matching local record are typically test payments or direct transfers sent outside the x402 flow.
4

Handle settlement outcomes

Before treating a payment as final, check 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.
Transfer status definitions are in the SDK reference.