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 project and install dependencies
Use your favorite package manager:npm
pnpm
bun
Step 2: Set your environment variables
Create a.env file in the project root 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)EVM_PRIVATE_KEY: Hex EVM private key of the paying accountSVM_PRIVATE_KEY: Base58 Solana private key of the paying account
EVM_RPC_URL to a JSON-RPC endpoint. When present, the client can perform
onchain reads, which enables gas-sponsoring extensions:
Step 3: Preview the client code
Createindex.ts: It loads your env, builds an x402Client and registers the exact and upto EVM schemes plus exact SVM, wraps Axios with wrapAxiosWithPayment, calls your endpoint, and prints the parsed payment result via x402HTTPClient.parsePaymentResult.
Step 4: Run the client
Your client is now making x402 payments!
Step 5: Test the client
You can test your client against a local server by running the Express example, Hono example, or Next.js example. You can also test your client against a live merchant for free. You will receive a full refund of any tokens that you send, and PayAI will pay for the network fees.x402 reference
For a deeper dive into message shapes, headers, verification and settlement responses, see the x402 Reference.Need help?
Join our Community
Have questions or want to connect with other developers? Join our Discord server.

