X402 Facilitator Integration
The Facilitator is the server-side settlement component in the X402 flow. The client is responsible for signing, and the Gateway or your server is responsible for calling the Facilitator's /verify and /settle.
Ace Data Cloud's production Facilitator address is:
https://facilitator.acedata.cloud
Source repository: https://github.com/AceDataCloud/FacilitatorX402
¶ v2 wire conventions
Ace Data Cloud's X402 flow fully uses the official x402 v2 and no longer accepts the v1 X-Payment request header. There are three points to note during integration:
- The request header is
PAYMENT-SIGNATURE, and its value is a base64-encoded JSON envelope. - The top level of the envelope must be
x402Version: 2, and theacceptedobject must be used to declare theschemeandnetworkselected for this request. networkuses the CAIP-2 identifier (such aseip155:8453) and cannot use abbreviations such asbase.
Envelope structure:
{
"x402Version": 2,
"accepted": {
"scheme": "exact",
"network": "eip155:8453"
},
"payload": { "...": "..." }
}
In addition to the JSON body, the 402 response also includes a PAYMENT-REQUIRED response header. Its value is a base64 encoding of the same challenge content, allowing clients to read payment requirements without parsing the body.
¶ Core interfaces
¶ GET /supported
View supported networks and schemes:
curl https://facilitator.acedata.cloud/supported
Example response:
{
"kinds": [
{ "x402Version": 2, "scheme": "exact", "network": "eip155:8453" },
{
"x402Version": 2,
"scheme": "upto",
"network": "eip155:8453",
"extra": { "facilitatorAddress": "0xd019238EAA8a9Ca13C5792Ca10B4029D6ce25708" }
},
{
"x402Version": 2,
"scheme": "exact",
"network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"extra": { "feePayer": "3SPm6qbgsDkj24MuR8Ss4sH97fziqyCiqFKDyeVU2igq" }
}
],
"extensions": [],
"signers": {
"eip155:*": [
"0xd019238EAA8a9Ca13C5792Ca10B4029D6ce25708"
],
"solana:*": ["3SPm6qbgsDkj24MuR8Ss4sH97fziqyCiqFKDyeVU2igq"]
}
}
Result description:
networkuses the CAIP-2 identifier, not abbreviations such asbaseorsolana./supportedindicates that the Facilitator has the corresponding verification and settlement capabilities.- Both Base and Solana support
exact;uptois currently available only on Base. signersare the addresses used by the Facilitator to submit settlement transactions.- Whether a specific API allows these options is still subject to that API's 402
accepts.
¶ POST /verify
Verify whether the PAYMENT-SIGNATURE sent by the client satisfies a payment requirement.
Request body:
{
"x402Version": 2,
"paymentPayload": {
"x402Version": 2,
"accepted": {
"scheme": "exact",
"network": "eip155:8453"
},
"payload": { "...": "..." }
},
"paymentRequirements": {
"scheme": "exact",
"network": "eip155:8453",
"asset": "0x...",
"amount": "95215",
"payTo": "0x...",
"maxTimeoutSeconds": 3600,
"extra": { "...": "..." }
}
}
The paymentRequirements fields in v2 are scheme, network, asset, amount, payTo, maxTimeoutSeconds, and extra, and the amount field is amount. The API 402 response's accepts[] also additionally returns maxAmountRequired for the client to read the maximum limit, but it is not a field in the Facilitator request body.
Successful response:
{
"isValid": true,
"invalidReason": null,
"payer": "0x..."
}
After decoding the PAYMENT-RESPONSE response header for a production order payment, it contains the settlement result. The program execution result for a Base order payment:
settle_header {'success': True, 'network': 'base', 'transaction': '0xfec08cc00a159ea1ec692b32faa9bf3d17595a986301169e689d94f58bc44151', 'errorReason': None}
order 78481793-304e-47f7-bc0c-8231aec9cc1e state Finished pay_way X402 price 1.2
explorer https://basescan.org/tx/0xfec08cc00a159ea1ec692b32faa9bf3d17595a986301169e689d94f58bc44151
transfer value 1200000 atomic USDC
Result description:
success=Trueindicates that Facilitator settlement was successful.transactionis the on-chain transaction hash, and the order'spay_idis also written with the same value.- The explorer shows a transfer of
1200000atomic USDC on Base. errorReason=Noneindicates that this settlement did not return a business error.
Verification failures also usually return HTTP 200, but isValid is false. The business side should read invalidReason, rather than only looking at the HTTP status code.
¶ POST /settle
Settle already verified authorization on-chain.
The request body is basically the same as /verify. The difference for upto is: paymentRequirements.amount is rewritten to the actual settlement amount during settlement; the signature limit is recorded by the Facilitator during the verify stage, and during settlement it validates that the actual amount does not exceed that limit.
Successful response:
{
"success": true,
"errorReason": null,
"transaction": "0x...",
"network": "eip155:8453",
"payer": "0x...",
"amount": "3"
}
If the actual upto amount is 0, transaction may be an empty string, indicating that there is no need to send an on-chain transaction.
¶ How the Ace Data Cloud Gateway uses Facilitator
The flow of the Ace Data Cloud API Gateway is as follows:
- The client requests the API for the first time, without
AuthorizationorPAYMENT-SIGNATURE. - The Gateway calculates the estimated price of the request and returns 402 and
accepts. - The client retries with
PAYMENT-SIGNATUREafter signing. - The Gateway decodes
PAYMENT-SIGNATUREand selects the matching payment requirement. - The Gateway calls Facilitator
/verify. - After
/verifysucceeds, the Gateway allows the request through to the target API. - After the target API returns, the Gateway calls Facilitator
/settleduring the/recordstage. - The Gateway writes the on-chain transaction hash into the usage record metadata.
exact settles the signed amount in step 7; upto writes amount based on actual usage in step 7, then settles the actual amount.
¶ How to integrate your own API
If you want your own API to support X402, you can implement it according to this structure:
- Prepare
paymentRequirementsfor each paid endpoint, including the network, amount, recipient address, asset address, and signature domain. - If the request does not have
PAYMENT-SIGNATURE, return HTTP 402 andaccepts. - If the request has
PAYMENT-SIGNATURE, Base64 decode it to obtainpaymentPayload. - Call Facilitator
/verify. - Execute the business logic after successful verification.
- Call Facilitator
/settleafter the business operation succeeds. - Save
payer,transaction,amount, andnetworkfor reconciliation.
The server must use its own generated paymentRequirements to call /verify and /settle; do not trust the amount, recipient address, or asset address returned by the client.
¶ Replay Protection
Facilitator records nonces. Authorizations with the same nonce cannot be verified and settled repeatedly.
This means:
- The client should sign a new envelope for each request;
- If
/settlehas submitted a transaction but has not yet been confirmed, you can retry/settlewith the same nonce for idempotent reconciliation; - Do not cache the same
PAYMENT-SIGNATUREand use it for multiple API calls.
¶ Common Errors
| Error | Common Cause |
|---|---|
Authorization nonce already processed |
The same PAYMENT-SIGNATURE was reused. |
Authorization destination mismatch |
The to in the client signature does not match the payTo in the payment requirement. |
invalid_upto_evm_payload_invalid_signature |
The chainId, facilitator, Permit2 domain, or signing address in the upto typed data does not match. |
PERMIT2_ALLOWANCE_REQUIRED |
The wallet has not yet approved sufficient USDC allowance for Permit2. |
Payer has insufficient USDC balance |
The payment wallet has insufficient USDC. |
Solana signer private key not configured |
Facilitator needs to sign as the fee payer, but the server lacks Solana signer configuration. |
