Architecture
Understanding how the X402 Facilitator enables gasless payments on ApeChain.
High-Level Overview
The X402 Facilitator acts as a trusted relayer between paying agents and the blockchain. It abstracts away gas management, transaction submission, and nonce tracking - letting developers focus on building great products.
System Components
Agent / Client
Your app or AI agent that needs to make payments. Uses the SDK to sign permits.
Facilitator API
Verifies permits and submits transactions. Pays gas fees on behalf of users.
Settlement Contract
On-chain contract that executes permit + transfer atomically.
Payment Flow
EIP-2612 Permits
The magic behind gasless payments is EIP-2612, an extension to ERC-20 tokens that allows approvals via signatures instead of transactions.
Traditional ERC-20 Flow (requires 2 transactions)
- User calls
approve(spender, amount)- pays gas - Spender calls
transferFrom()- pays gas
EIP-2612 Permit Flow (1 transaction, user pays 0 gas)
- User signs permit message off-chain - FREE
- Relayer calls
permit() + transferFrom()- relayer pays gas
Settlement Contract
The Settlement Contract is a simple, stateless contract that combines permit() andtransferFrom() into a single atomic transaction:
function settle(
address token,
address owner,
address recipient,
uint256 amount,
uint256 deadline,
uint8 v, bytes32 r, bytes32 s
) external {
// 1. Execute the permit (approve)
IERC20Permit(token).permit(
owner, address(this), amount, deadline, v, r, s
);
// 2. Transfer tokens to recipient
IERC20(token).transferFrom(owner, recipient, amount);
}Key properties:
- Atomic - If transfer fails, permit is not consumed
- Stateless - No storage, minimal gas overhead
- Non-custodial - Contract never holds funds
Security Model
✅ What the Facilitator CAN do
- • Submit your signed permit to the blockchain
- • Transfer the exact amount you authorized
- • Send funds only to the recipient you specified
❌ What the Facilitator CANNOT do
- • Change the recipient address
- • Transfer more than the signed amount
- • Reuse your permit (nonce protection)
- • Access funds without your signature
Network Details
| Network | ApeChain Mainnet |
| Chain ID | 33139 |
| RPC URL | https://apechain.calderachain.xyz/http |
| Block Explorer | apescan.io |
| Settlement Contract | 0xe24a8dbf205ee116c991f60686f778a2337a844f |
| Native Token | $APE (used for gas) |