x402-payments
Build x402 payment flows using MetaMask Smart Accounts Kit, machine to machine payments over HTTP with ERC-7710 delegations and ERC-7715 Advanced Permissions
- License 许可
- MIT
- 所属仓库
- MetaMask/skills
- 最近更新
- 2026-11-14
- Stars
- ★ 25
- Forks
- 11
01 前言 Front Matter
- 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
02 资源文件 3
- 参考文档workflows/delegation-payments.md2.7 KB
- 参考文档workflows/recurring-payments.md3.9 KB
- 参考文档workflows/seller-endpoint-setup.md2.6 KB
03 SKILL.md 正文
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-REQUIREDheader 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-SIGNATUREheader. - 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.
This approach enables buyers to pay from MetaMask wallet. Buyers can restrict delegations to specific facilitator addresses, amounts, and time windows using delegation scopes. They can also create long-lived delegations that allow recurring payments without re-signing for each request.
Workflows
| Workflow | Use case |
|---|---|
| Seller endpoint setup | You want to protect API endpoints with x402 payment requirements. |
| Delegation payments | You control the buyer smart account and want to automate payments programmatically. |
| Advanced Permissions (recurring) | You want to request a periodic budget from a MetaMask user for ongoing API access. Best for subscriptions and recurring usage. |
If the user hasn't specified which payment method they need, present the options.
Supported networks
| Network | Chain ID | Facilitator URL |
|---|---|---|
| Base | eip155:8453 | https://tx-sentinel-base-mainnet.dev-api.cx.metamask.io/platform/v2/x402 |
| Base Sepolia | eip155:84532 | https://tx-sentinel-base-sepolia.dev-api.cx.metamask.io/platform/v2/x402 |
| Monad | eip155:143 | https://tx-sentinel-monad-mainnet.dev-api.cx.metamask.io/platform/v2/x402 |
Resources
- x402 protocol: https://www.x402.org/
- Smart Accounts Kit docs: https://docs.metamask.io/smart-accounts-kit
- x402 overview
04 同仓库更多 Skills
recipe-plan-and-dispatch
Plan a ticket with the engineer before a recipe fix-bug or dev run. Agree the acceptance criteria and an implementation plan, write it as an approved plan file, and print the prompt that starts the run with any agent and model. Never edits product code or starts the run.
recipe-library-audit
Run every recipe of a team recipe library on one client with mm-harness, classify each result with the failing node and exact error, and review naming and composability. Produces a per-client table; changes nothing.
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
smart-accounts-kit
Build dApps with MetaMask Smart Accounts Kit — ERC-4337 smart accounts, delegations, and Advanced Permissions (ERC-7715)
oh-my-opencode
Multi-agent orchestration plugin for OpenCode. Use when the user wants to install, configure, or operate oh-my-opencode — including agent delegation, ultrawork mode, Prometheus planning, background tasks, category-based task routing, model resolution, tmux integration, or any oh-my-opencode feature. Covers installation, configuration, all agents (Sisyphus, Oracle, Librarian, Explore, Atlas, Prometheus, Metis, Momus), all categories, slash commands, hooks, skills, MCPs, and troubleshooting.
gator-cli
Use when you need to operate the @metamask/gator-cli to initialize profiles, upgrade EOA to EIP-7702, grant, redeem, and revoke ERC-7710 delegations, or inspect balances and delegations. Covers commands, required flags, grant scopes, redeem action types, configuration locations, and common usage flows.