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
Step 2: Set your environment variables
Create a.env file in the project root and set:
Step 3: Preview the server code
Createindex.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/paywallfor EVM chains orx402-solana-reactfor Solana
Going to production
The examples above use testnets. For Mainnet, update the routeβs network and any explicit scheme registrations together, use the matching asset and funded buyer, and verify the paid path. The Solana Mainnet example provides a complete tested configuration; adding credentials alone does not switch networks. This setup can serve ordinary exact mainnet payments in production within the free allowance β no API key or portal signup is required. Production readiness still includes normal controls such as secret management, monitoring, and failure handling. When you need paid capacity beyond the allowance, an autonomous agent can buy credits and receive an API key over x402; PayAI creates a wallet-owned agent account programmatically. You can also use the optional merchant dashboard. Add the resulting credentials to your.env:
@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.

