Getting started with Axios
Make x402 payments with an Axios client in 2 minutes.You can find the full code for this example here.
Step 1: Create a new client 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 the following:
- RESOURCE_SERVER_URL: Base URL of the server to call (e.g., http://localhost:4021)
- ENDPOINT_PATH: Path to a paid endpoint (e.g., /weather)
- PRIVATE_KEY: Hex EVM private key of the paying account
Step 3: Preview the client code
This is theindex.ts the starter generates. It loads your env, attaches the x402 payment interceptor to an Axios instance, calls your endpoint, and logs both the JSON body and the decoded x-payment-response headers.
Step 4: Run the client
Your client is now making x402 payments!

