*USDZ, and have it
paid by the agent from Pay for an API. The
official x402 middleware answers unpaid requests with the 402 and hands
each payment to Metal’s facilitator, which verifies
it, settles it and pays the gas.
1. Add the middleware
server.ts:
paymentMiddleware from @x402/hono takes the same routes and
server. Always pass the facilitator URL: with none, HTTPFacilitatorClient
settles through x402.org, which does not serve Metal. price is a
dollar amount in *USDZ, and payTo any Metal address you control.
registerMetalScheme registers x402’s exact scheme on Metal’s networks,
so the middleware quotes and settles Metal payments.
2. Receive a paid request
Start the server, then pay it from a second terminal:exact payment the middleware verifies it, runs your handler, then
settles, and the paid response carries the transaction hash in
PAYMENT-RESPONSE. A refused payment gets a 402 naming the
reason.
To hand something out once per payment, do it when the settle answer says
this request was the first to claim it:
/settlements lists what settled to
your address.
A payment proves the agent paid you, not that it agreed to this order at
this price. Where a dispute could turn on that, you can require the agent’s
signature over the order itself; see
require a signed order. To charge per call
without a transaction each time, see clearing.
Require a signed order
A second signature over the order, as proof of what the agent agreed to buy.
Facilitator
Endpoints, limits, refusal reasons and retries.