Skip to main content

Getting started with Hono

Start accepting x402 payments in your Hono server 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
This is the same dependency set as the upstream Hono example.

Step 2: Set your environment variables

Create a .env file in the project root and set:
@payai/facilitator automatically connects to the PayAI facilitator β€” no URL configuration needed.

Step 3: Preview the server code

Create index.ts: 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 x402 payments!

Step 5: Test the server

You can test payments against your server locally by:
  • Following the fetch example or the axios example
  • Creating a paywall using @x402/paywall for EVM chains or x402-solana-react for Solana

Going to production

This setup works on the free tier out of the box β€” no API keys required. When you’re ready for production, create a merchant account at merchant.payai.network, get your API keys, and add them to your .env:
The @payai/facilitator package automatically detects these environment variables and authenticates your requests to the facilitator. See Facilitator Pricing for tier details and Facilitator Authentication for the full protocol reference.

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.