Skip to main content

X402 flow

X402Flow handles the client-side x402 payment protocol for 4Mica. It turns the paymentRequirements from a 402 Payment Required response into a signed payment header (and an optional /settle call) that the facilitator accepts. Create a flow from your client:
Before signing, X402Flow resolves a tab by calling extra.tabEndpoint, which returns the next request id. Both signing methods always use EIP-712 and error if the scheme is not a 4Mica scheme.

What the SDK expects

At minimum, paymentRequirements must include:
  • scheme and network — the scheme must include 4mica (for example 4mica-credit).
  • payTo (recipient address), asset, and maxAmountRequired (v1) or amount (v2).
  • extra.tabEndpoint for tab resolution.

Version 1

Version 1 returns payment requirements in the JSON response body. Sign them into an X-PAYMENT header.

Version 2

Version 2 delivers requirements in a base64-encoded payment-required header and signs them into a PAYMENT-SIGNATURE header. If accepted.extra contains a complete validation policy, the SDK builds V2 claims automatically; otherwise it falls back to V1.

Settle through a facilitator

If your resource server proxies to a facilitator, reuse the SDK to settle a payment after verifying it. settlePayment POSTs to {facilitatorUrl}/settle.
settlePayment only hits /settle. Resource servers should still verify a payment before granting access.

Next steps

Server paywall

Gate any route behind an x402 payment.

Client operations

Deposit collateral, sign payments, and settle cleared cycles.