Skip to content

Add x402 server template#103

Merged
AyushBherwani1998 merged 11 commits into
mainfrom
feat/x402-server
May 15, 2026
Merged

Add x402 server template#103
AyushBherwani1998 merged 11 commits into
mainfrom
feat/x402-server

Conversation

@AyushBherwani1998
Copy link
Copy Markdown
Member

@AyushBherwani1998 AyushBherwani1998 commented May 12, 2026

Description

  • Adds x402 server template with ERC-7710 support

Note

Low Risk
Primarily adds a new scaffold template and a new framework option; risk is limited to template selection/type changes in the generator flow.

Overview
Adds a new node framework option to the generator and registers a new x402-server template under it.

Introduces a Node/Express x402 example server template (TypeScript) that gates GET /api/hello behind @x402/express payment middleware and enhances payment requirements with ERC-7710 metadata (via Erc7710ExactEvmScheme). Includes template project files (package.json, tsconfig.json, .env.example, .gitignore).

Reviewed by Cursor Bugbot for commit 405e91e. Bugbot is set up for automated code reviews on this repo. Configure here.

@AyushBherwani1998 AyushBherwani1998 requested review from a team as code owners May 12, 2026 02:54
@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 12, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

Comment thread a/src/index.ts Fixed
Comment thread templates/node/x402-server/src/index.ts Fixed
Comment thread a/package.json Outdated
Comment thread templates/node/x402-server/src/config.ts Outdated
Comment thread templates/node/x402-server/src/middleware.ts Outdated
Comment thread templates/node/x402-server/src/index.ts Fixed
Comment thread templates/node/x402-server/src/middleware.ts Outdated
Comment on lines +14 to +15
export const FACILITATOR_URL = process.env.FACILITATOR_URL!;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have a if (!FACILITATOR_URL) here too

Comment thread templates/node/x402-server/src/index.ts Outdated
app.use(express.json({ limit: "1mb" }));

async function fetchFacilitatorAddress(): Promise<Address> {
const res = await fetch(`${FACILITATOR_URL}/platform/v2/x402/supported`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

platform/v2/x402 is part of the facilitator url. This should just be ${FACILITATOR_URL}/supported

Comment thread templates/node/x402-server/src/index.ts Outdated
Comment on lines +22 to +23
const address = data.signers?.["eip155:*"]?.[0] as Address;
if (!address) throw new Error("Facilitator address not found in /supported response");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We append a single facilitator address in extras as an array - why not return all signers returned by the facilitator and let the buyer support all of them (they may need to support all signers in order to use the facilitator reliably, rather than pick and choose)

Comment thread templates/node/x402-server/src/middleware.ts Outdated
Comment on lines +120 to +121
const originalJson = res.json.bind(res);
res.json = function (body: unknown) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

monkey patching the res.json function here seems unstandard - is there a cleaner way to do this?

Comment thread templates/node/x402-server/src/types.ts Outdated
maxTimeoutSeconds: number;
extra: {
assetTransferMethod: string;
[key: string]: unknown;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we are effectively asserting the non-standard facilitators extra (or redeemers 🤞), can we add that to the type redeemers?: Address[]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the same for PaymentRequirements.


const originalJson = res.json.bind(res);
res.json = function (body: unknown) {
settlePayment(paymentPayload, paymentRequirements)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get this right, the protected response goes out before payment is confirmed. We should get the settleResult first before returning any data.

Comment thread templates/node/x402-server/src/index.ts Fixed
Comment thread templates/node/x402-server/.env.example Outdated
Comment thread templates/node/x402-server/.env.example Outdated
Comment thread templates/node/x402-server/src/utils.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1818944. Configure here.

Comment thread templates/node/x402-server/src/utils.ts Outdated
@AyushBherwani1998 AyushBherwani1998 requested a review from mj-kiwi May 14, 2026 03:29
Comment on lines +10 to +11
const NETWORK_ID = "eip155:8453";
const PORT = 4402;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these guy sbe environment vars?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessarily, do you want me to move them?

Comment thread templates/node/x402-server/src/index.ts Outdated
Comment thread templates/node/x402-server/src/scheme.ts Outdated
Comment thread templates/node/x402-server/src/scheme.ts Outdated
Copy link
Copy Markdown
Contributor

@jeffsmale90 jeffsmale90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@AyushBherwani1998 AyushBherwani1998 merged commit b8cbafc into main May 15, 2026
26 checks passed
@AyushBherwani1998 AyushBherwani1998 deleted the feat/x402-server branch May 15, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants