> For the complete documentation index, see [llms.txt](https://docs.wildmeta.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wildmeta.ai/trading-terminal/x402-support-and-extension/architecture-and-flow.md).

# Architecture & Flow

Below is a high-level description of how our extended x402 flow works:

1. The user connects their wallet (smart contract wallet supporting ERC-4337) and requests access to x402-protected content.
2. The server responds with HTTP 402 and includes in the response the payment requirements: network (chain), recipient address, payment amount, possibly token address, etc.
3. The client builds a UserOperation: the target callData is to effect the desired payment (e.g., transfer of ERC-20 token or other contract call) from the user’s smart wallet.
4. The user signs the UserOperation and sends it to the server (or the server provides a link or widget for submission).
5. The server forwards the signed UserOperation to the facilitator service.
6. The facilitator **verifies** the UserOperation (signature, nonce, correct target, payment amount, token, chain) and *simulates* it via dry-run to ensure it will succeed on-chain.
7. If validation passes, the server triggers the facilitator to **settle** the payment: the UserOperation is submitted to the chain (via bundler/entrypoint) and the facilitator monitors the transaction until confirmed.
8. Once settlement is complete and confirmed, the server returns the protected content to the user, granting access.

#### Components

* **Server (Resource Provider)**: hosts content or API behind x402. Responds with HTTP 402 payment requirement, receives signed UserOperation, forwards it to facilitator, waits for confirmation, then delivers content.
* **Client SDK**: runs in browser/app. Reads the HTTP 402 response, builds user-friendly UI showing payment details, interacts with user wallet (smart-wallet) to construct and sign UserOperation, and sends signed payload back.
* **Facilitator Service**: This is a trusted back-end (ideally TEE-backed for integrity) that:
  * Accepts signed UserOperations (opaque bytes)
  * Validates signature, target callData, payment details
  * Simulates the UserOperation on respective chain to ensure success
  * Submits to bundler/entrypoint and tracks the resulting transaction until confirmed
  * Notifies server of success or failure
* **Smart Wallet / User’s Account Abstraction Setup**: The user holds a wallet contract (smart account) that supports ERC-4337 operations; the SDK helps prepare the UserOperation struct.
