402 Payment Required response into a signed Hedera transfer. The client does not need its own fee-paying node: a facilitator covers the network fee and submits the transaction.
Register the Hedera scheme
Install and import the client packages, then register theexact scheme with a signer for your account:
client.ts
Make a paid request
Once the scheme is registered, requests to x402-gated endpoints are handled automatically:- The client calls the resource (for example,
GET /weather) without any extra headers. - The server replies with
402 Payment Requiredand thePaymentRequirements, including the facilitatorfeePayer. - The client builds, signs, and Base64-encodes a
TransferTransactionto thepayToaccount. - The client resubmits the request with the
PaymentPayloadin theX-Paymentheader (or equivalent).
pay helpers if you want explicit control over signing and retries.
Requirements
- The client account must hold the asset being paid (HBAR or the relevant HTS token).
- For HTS tokens, the client account must be associated with that token.
- Use a facilitator that advertises the Hedera network you are paying on.
Further reading
Hedera's exact scheme
Message shapes, assets, and safety checks.
Accept x402 on Hedera
Add payment gating to a resource server.