Skip to content

Commit 17f6ba6

Browse files
furiosaRyan R. Fox
authored andcommitted
Add multi-method /protected endpoint to e2e servers
Create new /protected endpoint that accepts multiple payment methods in preference order: 1. Base USDC EIP-3009 2. Base WETH Permit2 3. Solana USDC Updated express and hono servers with the new endpoint configuration and corresponding route handlers. Test configs updated to declare the new multiMethod endpoint.
1 parent 4044964 commit 17f6ba6

5 files changed

Lines changed: 158 additions & 2 deletions

File tree

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ __pycache__/
1111
e2e/facilitators/external-proxies/*
1212
!e2e/facilitators/external-proxies/README.md
1313
<<<<<<< HEAD
14+
<<<<<<< HEAD
1415
typescript/package-lock.json
1516
# Gas Town infrastructure
1617
.beads/
1718
AGENTS.md
1819
=======
1920
typescript/package-lock.json.beads/
2021
>>>>>>> ee4d12e9 (Add .beads to gitignore)
22+
=======
23+
typescript/package-lock.json
24+
25+
# Gas Town (added by gt)
26+
.runtime/
27+
.claude/
28+
.beads/
29+
.logs/
30+
>>>>>>> a9e98342 (Add multi-method /protected endpoint to e2e servers)

e2e/servers/express/index.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,55 @@ console.log(`Using remote facilitator at: ${facilitatorUrl}`);
6565
app.use(
6666
paymentMiddleware(
6767
{
68+
// Multi-method endpoint - accepts multiple payment methods in preference order
69+
"GET /protected": {
70+
accepts: [
71+
// 1. Base USDC EIP-3009 (highest preference)
72+
{
73+
payTo: EVM_PAYEE_ADDRESS,
74+
scheme: "exact",
75+
price: "$0.001",
76+
network: EVM_NETWORK,
77+
},
78+
// 2. Base WETH Permit2
79+
{
80+
payTo: EVM_PAYEE_ADDRESS,
81+
scheme: "exact",
82+
network: EVM_NETWORK,
83+
price: {
84+
amount: "1000",
85+
asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", // Base Sepolia USDC
86+
extra: {
87+
assetTransferMethod: "permit2",
88+
},
89+
},
90+
},
91+
// 3. Solana USDC (lowest preference)
92+
{
93+
payTo: SVM_PAYEE_ADDRESS,
94+
scheme: "exact",
95+
price: "$0.001",
96+
network: SVM_NETWORK,
97+
},
98+
],
99+
extensions: {
100+
...declareDiscoveryExtension({
101+
output: {
102+
example: {
103+
message: "Multi-method endpoint accessed successfully",
104+
timestamp: "2024-01-01T00:00:00Z",
105+
},
106+
schema: {
107+
properties: {
108+
message: { type: "string" },
109+
timestamp: { type: "string" },
110+
},
111+
required: ["message", "timestamp"],
112+
},
113+
},
114+
}),
115+
},
116+
},
68117
// Route-specific payment configuration
69118
"GET /protected-eip3009": {
70119
accepts: {
@@ -157,7 +206,23 @@ app.use(
157206
);
158207

159208
/**
160-
* Protected endpoint - requires payment to access
209+
* Multi-method protected endpoint - accepts multiple payment methods
210+
*
211+
* This endpoint demonstrates a resource protected by x402 payment middleware
212+
* that accepts multiple payment methods in preference order:
213+
* 1. Base USDC EIP-3009
214+
* 2. Base WETH Permit2
215+
* 3. Solana USDC
216+
*/
217+
app.get("/protected", (req, res) => {
218+
res.json({
219+
message: "Multi-method endpoint accessed successfully",
220+
timestamp: new Date().toISOString(),
221+
});
222+
});
223+
224+
/**
225+
* Protected EIP-3009 endpoint - requires payment to access
161226
*
162227
* This endpoint demonstrates a resource protected by x402 payment middleware.
163228
* Clients must provide a valid payment signature to access this endpoint.
@@ -238,6 +303,7 @@ app.listen(parseInt(PORT), () => {
238303
║ SVM Payee: ${SVM_PAYEE_ADDRESS}
239304
║ ║
240305
║ Endpoints: ║
306+
║ • GET /protected (multi-method payment) ║
241307
║ • GET /protected-eip3009 (EIP-3009 payment) ║
242308
║ • GET /protected-svm (SVM payment) ║
243309
║ • GET /protected-permit2 (Permit2 payment) ║

e2e/servers/express/test.config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
"bazaar"
88
],
99
"endpoints": [
10+
{
11+
"path": "/protected",
12+
"method": "GET",
13+
"description": "Multi-method endpoint accepting EIP-3009, Permit2, or SVM payment",
14+
"requiresPayment": true,
15+
"multiMethod": true
16+
},
1017
{
1118
"path": "/protected-eip3009",
1219
"method": "GET",

e2e/servers/hono/index.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,55 @@ app.use(
6969
"*",
7070
paymentMiddleware(
7171
{
72+
// Multi-method endpoint - accepts multiple payment methods in preference order
73+
"GET /protected": {
74+
accepts: [
75+
// 1. Base USDC EIP-3009 (highest preference)
76+
{
77+
payTo: EVM_PAYEE_ADDRESS,
78+
scheme: "exact",
79+
price: "$0.001",
80+
network: EVM_NETWORK,
81+
},
82+
// 2. Base WETH Permit2
83+
{
84+
payTo: EVM_PAYEE_ADDRESS,
85+
scheme: "exact",
86+
network: EVM_NETWORK,
87+
price: {
88+
amount: "1000",
89+
asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", // Base Sepolia USDC
90+
extra: {
91+
assetTransferMethod: "permit2",
92+
},
93+
},
94+
},
95+
// 3. Solana USDC (lowest preference)
96+
{
97+
payTo: SVM_PAYEE_ADDRESS,
98+
scheme: "exact",
99+
price: "$0.001",
100+
network: SVM_NETWORK,
101+
},
102+
],
103+
extensions: {
104+
...declareDiscoveryExtension({
105+
output: {
106+
example: {
107+
message: "Multi-method endpoint accessed successfully",
108+
timestamp: "2024-01-01T00:00:00Z",
109+
},
110+
schema: {
111+
properties: {
112+
message: { type: "string" },
113+
timestamp: { type: "string" },
114+
},
115+
required: ["message", "timestamp"],
116+
},
117+
},
118+
}),
119+
},
120+
},
72121
// Route-specific payment configuration
73122
"GET /protected-eip3009": {
74123
accepts: {
@@ -126,7 +175,23 @@ app.use(
126175
);
127176

128177
/**
129-
* Protected endpoint - requires payment to access
178+
* Multi-method protected endpoint - accepts multiple payment methods
179+
*
180+
* This endpoint demonstrates a resource protected by x402 payment middleware
181+
* that accepts multiple payment methods in preference order:
182+
* 1. Base USDC EIP-3009
183+
* 2. Base WETH Permit2
184+
* 3. Solana USDC
185+
*/
186+
app.get("/protected", (c) => {
187+
return c.json({
188+
message: "Multi-method endpoint accessed successfully",
189+
timestamp: new Date().toISOString(),
190+
});
191+
});
192+
193+
/**
194+
* Protected EIP-3009 endpoint - requires payment to access
130195
*
131196
* This endpoint demonstrates a resource protected by x402 payment middleware.
132197
* Clients must provide a valid payment signature to access this endpoint.
@@ -198,6 +263,7 @@ console.log(`
198263
║ SVM Payee: ${SVM_PAYEE_ADDRESS}
199264
║ ║
200265
║ Endpoints: ║
266+
║ • GET /protected (multi-method payment) ║
201267
║ • GET /protected-eip3009 (requires $0.001 USDC) ║
202268
║ • GET /protected-svm (requires $0.001 USDC payment) ║
203269
║ • GET /health (no payment required) ║

e2e/servers/hono/test.config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
"bazaar"
88
],
99
"endpoints": [
10+
{
11+
"path": "/protected",
12+
"method": "GET",
13+
"description": "Multi-method endpoint accepting EIP-3009, Permit2, or SVM payment",
14+
"requiresPayment": true,
15+
"multiMethod": true
16+
},
1017
{
1118
"path": "/protected-eip3009",
1219
"method": "GET",

0 commit comments

Comments
 (0)