Add x402 server template#103
Conversation
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
| export const FACILITATOR_URL = process.env.FACILITATOR_URL!; | ||
|
|
There was a problem hiding this comment.
We should probably have a if (!FACILITATOR_URL) here too
| app.use(express.json({ limit: "1mb" })); | ||
|
|
||
| async function fetchFacilitatorAddress(): Promise<Address> { | ||
| const res = await fetch(`${FACILITATOR_URL}/platform/v2/x402/supported`); |
There was a problem hiding this comment.
platform/v2/x402 is part of the facilitator url. This should just be ${FACILITATOR_URL}/supported
| const address = data.signers?.["eip155:*"]?.[0] as Address; | ||
| if (!address) throw new Error("Facilitator address not found in /supported response"); |
There was a problem hiding this comment.
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)
| const originalJson = res.json.bind(res); | ||
| res.json = function (body: unknown) { |
There was a problem hiding this comment.
monkey patching the res.json function here seems unstandard - is there a cleaner way to do this?
| maxTimeoutSeconds: number; | ||
| extra: { | ||
| assetTransferMethod: string; | ||
| [key: string]: unknown; |
There was a problem hiding this comment.
because we are effectively asserting the non-standard facilitators extra (or redeemers 🤞), can we add that to the type redeemers?: Address[]
There was a problem hiding this comment.
I guess the same for PaymentRequirements.
|
|
||
| const originalJson = res.json.bind(res); | ||
| res.json = function (body: unknown) { | ||
| settlePayment(paymentPayload, paymentRequirements) |
There was a problem hiding this comment.
If I get this right, the protected response goes out before payment is confirmed. We should get the settleResult first before returning any data.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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.
| const NETWORK_ID = "eip155:8453"; | ||
| const PORT = 4402; |
There was a problem hiding this comment.
should these guy sbe environment vars?
There was a problem hiding this comment.
not necessarily, do you want me to move them?

Description
Note
Low Risk
Primarily adds a new scaffold template and a new
frameworkoption; risk is limited to template selection/type changes in the generator flow.Overview
Adds a new
nodeframework option to the generator and registers a newx402-servertemplate under it.Introduces a Node/Express x402 example server template (TypeScript) that gates
GET /api/hellobehind@x402/expresspayment middleware and enhances payment requirements with ERC-7710 metadata (viaErc7710ExactEvmScheme). 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.