| name | x402-payments |
| description | Build x402 payment flows using MetaMask Smart Accounts Kit, machine to machine payments over HTTP with ERC-7710 delegations and ERC-7715 Advanced Permissions |
x402 Payments
x402 is an open payment protocol that uses the HTTP 402 status code to enable programmatic, machine-to-machine payments over HTTP. It lets servers charge for API access without requiring traditional payment infrastructure, buyer accounts, or API keys.
When to use
- You want to charge for API access using onchain payments.
- You want to build AI agents that pay per request for API resources.
- You want to enable micro payments for premium data or services.
- You want to set up recurring payments with periodic budgets.
- You want to use MetaMask smart account delegations for x402 settlement.
Installation
npm install @x402/core @x402/fetch @metamask/x402 @metamask/smart-accounts-kit
For seller endpoints:
npm install @x402/core @x402/express @metamask/x402
How x402 works
- The buyer sends a request to a protected endpoint.
- The server responds with HTTP 402 and a
PAYMENT-REQUIRED header containing payment terms.
- The buyer creates a payment payload (delegation or permission) matching the terms.
- The buyer resends the request with the payment in the
PAYMENT-SIGNATURE header.
- The server validates the payment through a facilitator and returns the resource.
x402 ERC-7710 payments
The standard x402 protocol supports direct token transfers (using ERC-20 Permit2 or EIP-3009). ERC-7710 extends this by enabling delegation-based payments from MetaMask smart accounts.
With ERC-7710, a buyer's smart account creates a delegation that authorizes the facilitator to transfer tokens on their behalf. The buyer doesn't sign a direct token approval. Instead, they sign a delegation that the facilitator redeems during settlement.