Getting started with Express
Start accepting x402 payments in your Express server in 2 minutes.You can find the full code for this example here.
Step 1: Create a new server from the starter template
Use your favorite package manager.npm (npx)
pnpm
bun
Step 2: Set your environment variables
Open your generated project’s.env
and set:
FACILITATOR_URL
: Facilitator base URL (defaults to: https://facilitator.payai.network)NETWORK
: Network to use for the facilitator (default:base-sepolia
)ADDRESS
: Wallet public address to receive payments to
Step 3: Preview the server code
This is theindex.ts
the starter generates. It loads your env, applies the x402 payment middleware, defines example routes, and logs the server URL.
Step 4: Run the server
Your server is now accepting 402 payments!
Step 5: Test the server
You can test payments against your server locally by following the fetch example or the axios example.Need help?
Join our Community
Have questions or want to connect with other developers? Join our Discord server.