@@ -14,8 +14,10 @@ In this guide, you build a Node.js server that charges for HTTP API access using
1414[ x402] ( https://www.x402.org/ ) and accepts [ ERC-7710] ( https://eips.ethereum.org/EIPS/eip-7710 ) delegation
1515payments verified through the MetaMask facilitator.
1616
17- You use the official [ ` @x402/express ` ] ( https://www.npmjs.com/package/@x402/express ) middleware with a custom ERC-7710 scheme that routes
18- verification and settlement through the MetaMask facilitator.
17+ You use the official [ ` @x402/express ` ] ( https://www.npmjs.com/package/@x402/express ) middleware with the
18+ [ ` @metamask/x402 ` ] ( https://www.npmjs.com/package/@metamask/x402 )
19+ package, which provides an ERC-7710 server scheme that routes verification and settlement
20+ through the MetaMask facilitator.
1921
2022## Prerequisites
2123
@@ -24,70 +26,36 @@ verification and settlement through the MetaMask facilitator.
2426- A seller payout address to receive funds (for example, a
2527 [ MetaMask wallet] ( https://metamask.io/download ) address).
2628
29+ ## Facilitator URLs
30+
31+ The following table lists the available MetaMask facilitator endpoints:
32+
33+ | Name | ID | URL |
34+ | ------------ | -------------- | --------------------------------------------------------------------- |
35+ | Base | ` eip155:8453 ` | https://tx-sentinel-base-mainnet.api.cx.metamask.io/platform/v2/x402 |
36+ | Base Sepolia | ` eip155:84532 ` | https://tx-sentinel-base-sepolia.api.cx.metamask.io/platform/v2/x402 |
37+ | Monad | ` eip155:143 ` | https://tx-sentinel-monad-mainnet.api.cx.metamask.io/platform/v2/x402 |
38+
2739## Steps
2840
2941### 1. Install the dependencies
3042
3143``` bash npm2yarn
32- npm install @x402/core @x402/evm @x402/express cors express
44+ npm install @metamask/x402 @ x402/core @x402/evm @x402/express cors express
3345```
3446
35- ### 2. Create the ERC-7710 scheme
36-
37- Create a custom scheme that extends ` ExactEvmScheme ` from ` @x402/evm ` to add ERC-7710
38- delegation support.
39-
40- The scheme overrides ` enhancePaymentRequirements ` to set ` assetTransferMethod ` to ` erc7710 `
41- and include the facilitator addresses so buyers can scope their delegation to a specific
42- set of facilitators before creating the payment payload.
43-
44- ``` ts
45- import { ExactEvmScheme } from ' @x402/evm/exact/server'
46- import type { PaymentRequirements , SupportedKind } from ' @x402/core/types'
47- import type { FacilitatorClient } from ' @x402/core/server'
48-
49- export class Erc7710ExactEvmScheme extends ExactEvmScheme {
50- constructor (private readonly facilitatorClient : FacilitatorClient ) {
51- super ()
52- }
53-
54- async enhancePaymentRequirements(
55- paymentRequirements : PaymentRequirements ,
56- supportedKind : SupportedKind ,
57- facilitatorExtensions : string []
58- ): Promise <PaymentRequirements > {
59- const enhanced = await super .enhancePaymentRequirements (
60- paymentRequirements ,
61- supportedKind ,
62- facilitatorExtensions
63- )
64-
65- const supported = await this .facilitatorClient .getSupported ()
66- const facilitators = [
67- ... (supported .signers [paymentRequirements .network ] ?? []),
68- ... (supported .signers [' eip155:*' ] ?? []),
69- ]
70-
71- return {
72- ... enhanced ,
73- extra: {
74- ... enhanced .extra ,
75- assetTransferMethod: ' erc7710' ,
76- facilitators ,
77- },
78- }
79- }
80- }
81- ```
47+ ### 2. Configure middleware
8248
83- ### 3. Configure the server
49+ Set up the Express server with the x402 ` paymentMiddleware ` and the ` x402ExactEvmErc7710ServerScheme `
50+ from ` @metamask/x402 ` .
51+ The scheme automatically adds payment requirements with ERC-7710 fields when
52+ ` assetTransferMethod ` is set to ` erc7710 ` in the route configuration.
8453
85- Set up the Express server with the x402 ` paymentMiddleware ` and the custom ERC-7710 scheme.
8654The ` paymentMiddleware ` intercepts requests to protected routes and handles the full x402 payment
8755flow, including requirements advertisement, verification, and settlement.
8856
8957In this example, you create a protected ` GET /api/hello ` endpoint that charges 0.01 USDC on
90- Base mainnet .
58+ Base Sepolia .
9159Replace the payout address in ` src/config.ts ` with your own seller wallet address.
9260
9361<Tabs >
@@ -96,9 +64,8 @@ Replace the payout address in `src/config.ts` with your own seller wallet addres
9664``` ts
9765import express , { type Request , type Response } from ' express'
9866import cors from ' cors'
99- import { paymentMiddleware } from ' @x402/express'
100- import { x402ResourceServer } from ' @x402/core/server'
101- import { Erc7710ExactEvmScheme } from ' ./scheme.js'
67+ import { paymentMiddleware , x402ResourceServer } from ' @x402/express'
68+ import { x402ExactEvmErc7710ServerScheme } from ' @metamask/x402'
10269import { NETWORK_ID , PORT , payToAddress , facilitatorClient } from ' ./config.js'
10370
10471const app = express ()
@@ -114,6 +81,9 @@ app.use(
11481 price: ' $0.01' ,
11582 network: NETWORK_ID ,
11683 payTo: payToAddress ,
84+ extra: {
85+ assetTransferMethod: ' erc7710' ,
86+ },
11787 },
11888 ],
11989 description: ' Access to protected resource' ,
@@ -122,7 +92,7 @@ app.use(
12292 },
12393 new x402ResourceServer (facilitatorClient ).register (
12494 NETWORK_ID ,
125- new Erc7710ExactEvmScheme ( facilitatorClient )
95+ new x402ExactEvmErc7710ServerScheme ( )
12696 )
12797 )
12898)
@@ -143,15 +113,15 @@ app.listen(PORT, () => {
143113``` ts
144114import { HTTPFacilitatorClient } from ' @x402/core/server'
145115
146- export const NETWORK_ID = ' eip155:8453 '
116+ export const NETWORK_ID = ' eip155:84532 '
147117export const PORT = 4402
148118
149119// Replace with your seller payout address.
150120export const payToAddress = ' 0x<PAY_TO_ADDRESS>'
151121
152- // MetaMask facilitator base URL for x402 on Base mainnet .
122+ // MetaMask facilitator base URL for x402 on Base Sepolia .
153123export const facilitatorClient = new HTTPFacilitatorClient ({
154- url: ' https://tx-sentinel-base-mainnet.dev- api.cx.metamask.io/platform/v2/x402' ,
124+ url: ' https://tx-sentinel-base-sepolia. api.cx.metamask.io/platform/v2/x402' ,
155125})
156126```
157127
0 commit comments