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:
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:
schemeandnetwork— the scheme must include4mica(for example4mica-credit).payTo(recipient address),asset, andmaxAmountRequired(v1) oramount(v2).extra.tabEndpointfor tab resolution.
Version 1
Version 1 returns payment requirements in the JSON response body. Sign them into anX-PAYMENT header.
Version 2
Version 2 delivers requirements in a base64-encodedpayment-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.