Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cors from "cors";
import routes from "./routes";
import bodyParser from "body-parser";
import dotenv from "dotenv";
import { createPaymentMiddleware } from "./lib/x402/paymentMiddleware";

dotenv.config();

Expand All @@ -15,6 +16,7 @@ app.use(express.urlencoded({ extended: false, limit: "10mb" }));
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(createPaymentMiddleware());
app.use("/api", routes);

app.listen(port, () => {
Expand Down
36 changes: 36 additions & 0 deletions lib/x402/paymentMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { paymentMiddleware } from "x402-express";
import type { RequestHandler } from "express";

const RECEIVING_WALLET_ADDRESS = "0x749B7b7A6944d72266Be9500FC8C221B6A7554Ce";
const FACILITATOR_URL = "https://x402.org/facilitator";

type RoutesConfig = Parameters<typeof paymentMiddleware>[1];

const routeConfig = {
"GET /api/image/generate": {
price: "$0.001",
network: "base-sepolia" as const,
config: {
description: "Generate images using AI",
inputSchema: {
type: "object" as const,
properties: {
location: { type: "string" as const, description: "City name" },
},
},
outputSchema: {
type: "object" as const,
properties: {
weather: { type: "string" as const },
temperature: { type: "number" as const },
},
},
},
},
} as RoutesConfig;

export const createPaymentMiddleware = (): RequestHandler => {
return paymentMiddleware(RECEIVING_WALLET_ADDRESS, routeConfig, {
url: FACILITATOR_URL,
});
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@browserbasehq/stagehand": "^1.10.1",
"@coinbase/coinbase-sdk": "^0.21.0",
"@coinbase/x402": "^0.7.3",
"@langchain/anthropic": "^0.3.15",
"@langchain/core": "^0.3.42",
"@langchain/langgraph": "^0.2.55",
Expand Down Expand Up @@ -46,10 +47,11 @@
"prettier": "^3.4.1",
"socket.io": "^4.8.1",
"stripe": "^18.5.0",
"tsconfig-paths": "^4.2.0",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"uuid": "^11.0.5",
"viem": "^2.37.5",
"x402-express": "^0.7.3",
"zod": "^4.1.12"
},
"devDependencies": {
Expand Down
Loading