Starter for running an x402 fetch client.
You can find the upstream example at coinbase/x402 → examples/typescript/clients/fetch.
- Node.js: 18 or newer
Use your preferred package manager to scaffold:
npm exec @payai/x402-fetch-starter -- my-x402-apppnpm dlx @payai/x402-fetch-starter my-x402-appbunx @payai/x402-fetch-starter my-x402-appThen inside your new app:
npm run devWhen you run the generated app, index.ts will:
- Load environment variables from
.env(for example:RESOURCE_SERVER_URL,ENDPOINT_PATH,PRIVATE_KEY). - Create a wallet client and wrap the native
fetchwith x402 usingwrapFetchWithPayment. - Call your configured endpoint at
${RESOURCE_SERVER_URL}${ENDPOINT_PATH}. - Log two things to the console:
- The parsed JSON response body
- The decoded
x-payment-responseheaders (useful for inspecting payment receipts/metadata)
Below are notes on the starter itself, which creates the example that devs use to get started.
- Workflow:
.github/workflows/sync.yml - Triggered hourly (cron) and on manual dispatch.
- Steps (high level):
- Sparse clone upstream
coinbase/x402and restrict toexamples/typescript/clients/fetch. - Resolve latest
x402-fetchversion from npm (best-effort). - Mirror files into
vendor/upstream/(transient; ignored in git and cleaned up). - Run
scripts/sanitize.shto:- Copy all files from
vendor/upstream/intotemplate/(root of the template), preserving structure. - Remove any legacy
template/src/directory. - Refresh
NOTICEwith the upstream commit and clean upvendor/andupstream/directories.
- Copy all files from
- Inject the resolved
x402-fetchversion intotemplate/package.json(replacing any workspace reference). - Open a PR with the changes using
peter-evans/create-pull-request.
- Sparse clone upstream
Notes:
- If
npm view x402-fetch versionfails, the workflow falls back to0.0.0and will skip injecting the dependency until it is available. - The template mirrors the upstream example at the template root (no
src/in the template). Your generated app runs from its root.
# run the sanitize/mapping script locally (after an upstream sync or manual vendor update)
scripts/sanitize.sh examples/typescript/clients/fetch <commit-sha>Key files:
template/– shipped starter template; mirrors upstream example at rootvendor/upstream/– transient mirror used during sync (gitignored and cleaned).github/workflows/sync.yml– sync/PR workflowscripts/sanitize.sh– maps upstream example intotemplate/(root)bin/create.js– CLI that scaffolds a new project fromtemplate/
- The
Releaseworkflow publishes on pushes tomain. - Requires
NPM_TOKENsecret configured in the repo.
Apache-2.0. Portions are derived from coinbase/x402 (see NOTICE, LICENSE, and upstream notices).