Skip to content

docs(x402): metered upto settlement in seller quickstart#20

Merged
hayarobi merged 2 commits into
mainfrom
feat/x402-seller-upto-settlement
Jul 13, 2026
Merged

docs(x402): metered upto settlement in seller quickstart#20
hayarobi merged 2 commits into
mainfrom
feat/x402-seller-upto-settlement

Conversation

@nolnol3

@nolnol3 nolnol3 commented Jul 13, 2026

Copy link
Copy Markdown
Member

What

Fills two gaps in the x402 seller/settlement docs — both missing from our docs and upstream — needed by gateway/LLM sellers (e.g. hpp-router #150).

1. Metered upto settlement (quickstart-sellers → "Settling the actual amount")

Sellers advertising upto only learned to set the max, not how to settle the actual usage. Adds the setSettlementOverrides recipe (settle ≤ max, "0" ⇒ no onchain tx), generic mechanics linked upstream, HPP facts stated here, and a gateway/non-Node note (sidecar vs native).

2. Serve-then-settle contract + settlement hooks (how-it-works, quickstart-sellers → "Reacting to settlement")

The observable timing was undocumented everywhere:

  • how-it-works: the response is held until settlement completes → a 200 (with payment-response receipt) means settled onchain; a settle failure returns an error, not the resource (work done but not delivered/charged). HPP settles synchronously (waits for onchain confirm, p50 ~1.3s).
  • seller quickstart: res.json() ≠ settled; react via resourceServer.onAfterSettle / onSettleFailure (ctx.result = outcome); full hook set linked upstream.

Verification (HPP Sepolia, onchain)

  • Partial: max 10000, override 1000 → onchain transfer = 1000 (tx 0x164163eb…).
  • Zero: { amount: "0" } → receipt transaction: "" (no onchain tx).
  • Buyer: 200 → decoded payment-response = { success, transaction, payer, network }.
  • Seller hook: onAfterSettle fires after settlement; ctx.result = { success, payer, transaction, network }.

Every claim in the added examples is verified against live onchain behavior. Content-only, additive; page compiles (onBrokenLinks: 'throw').

Sellers advertising `upto` only learned how to set the max, not how to
settle the actual usage afterwards. Add a "Settling the actual amount"
section covering `setSettlementOverrides` (settle ≤ max, "0" = no onchain
tx), with the generic mechanics linked to the upstream x402 docs and only
the HPP-specific facts stated here (both facilitators support upto variable
settlement; /supported to confirm). Adds a gateway/non-Node note (sidecar
vs native facilitator HTTP) for API-gateway sellers.
@nolnol3
nolnol3 requested a review from hayarobi July 13, 2026 07:44
Neither our docs nor upstream explained the observable serve-then-settle
timing. Add it where integrators need it:

- how-it-works: the response is held until settlement completes, so a 200
  (with a payment-response receipt) means settled onchain; a settle failure
  returns an error instead of the resource (work done but not delivered/
  charged). HPP settles synchronously (waits for onchain confirm, p50 ~1.3s).
- seller quickstart: res.json() != settled; react to settlement via
  resourceServer.onAfterSettle / onSettleFailure (ctx.result = outcome),
  with the full hook set linked upstream.

All verified onchain on Sepolia (partial settle, settle-0, buyer receipt
decode, onAfterSettle firing with ctx.result).

@hayarobi hayarobi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hayarobi
hayarobi merged commit 639ef6c into main Jul 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants