NavenDocs
NavenDocs
Introduction
QuickstartHow x402 Payments WorkBuyer/Client GuideNaven CLISeller/Server Guide
Back to Naven Network
Getting Started

Naven CLI

Create and customize an x402 paid server from the official Naven template.

The Naven CLI scaffolds a standalone Bun and Hono server that accepts x402 v2 payments through the Naven facilitator. The server template is bundled with the CLI, so one command creates a complete project without cloning this repository.

The CLI currently supports the server template.

Requirements

  • Bun 1.2 or later
  • An EVM address that will receive payments

Create a server

Run the latest CLI without installing it globally:

bunx naven-cli@latest create server my-server
cd my-server

The CLI copies the server template, creates .env from .env.example, assigns a package name based on the directory, and runs bun install.

Set your payment recipient and start the server:

# .env
X402_PAY_TO=0xYourEvmAddress
bun run dev

Request http://localhost:4021/weather. An unpaid request should return 402 Payment Required with a PAYMENT-REQUIRED header.

Install the command globally

If you use the CLI regularly, install the naven command:

bun add --global naven-cli@latest
naven --version
naven create server my-server

Run the same install command again to update to the latest release.

Command reference

naven create server [directory] [options]
Argument or optionBehavior
directoryDestination directory. Defaults to my-server.
--no-installCopy the template without running bun install.
-h, --helpShow help for the CLI or command.
-v, --versionShow the installed CLI version.

The destination can be new or an existing empty directory. The CLI refuses to overwrite a non-empty directory.

To inspect the files before installing dependencies:

bunx naven-cli@latest create server my-server --no-install
cd my-server
bun install

What the server template includes

my-server/
├── .env                 # local configuration; do not commit
├── .env.example         # safe configuration template
├── Dockerfile
├── README.md
├── package.json
├── scripts/
│   └── test-challenge.ts
└── src/
    ├── app.ts           # Hono routes and x402 middleware
    ├── config.ts        # network, asset, price, and environment validation
    └── index.ts         # Bun server entry point

The generated server provides:

  • GET /health, a free health endpoint
  • GET /weather, a paid example endpoint
  • x402 v2 verification and settlement through the Naven facilitator
  • Robinhood Chain USDG defaults
  • CORS headers for x402 payment requests and responses
  • TypeScript checking, a challenge smoke test, and Docker support

The template is a starting point, not a runtime dependency on the CLI. After generation, the new project is independent and you can change any file.

Generated scripts

CommandPurpose
bun run devStart the server with hot reload.
bun run startStart the server without hot reload.
bun run typecheckCheck the TypeScript project.
bun run test:challengeVerify the paid route returns a valid x402 challenge without spending funds.
bun run checkRun the typecheck and challenge test.

Configure the template

The CLI creates .env automatically. These variables control deployment-specific behavior:

VariableRequiredDefaultPurpose
X402_PAY_TOYesNoneEVM address that receives payments.
PUBLIC_URLNohttp://localhost:4021Public HTTP(S) origin buyers use to reach the server.
PORTNo4021Local listening port.
FACILITATOR_URLNohttps://facilitator.naven.networkFacilitator used to verify and settle payments.
CORS_ORIGINNo*Browser origin allowed to call the server.

Payment terms are defined in src/config.ts. Route metadata and handlers are defined in src/app.ts. When you rename a paid endpoint, update both the paymentMiddleware key and the matching Hono route.

For a complete customization and deployment walkthrough, continue to the Seller/Server Guide.

Troubleshooting

The target directory is not empty

Choose a new directory or move the existing files. The CLI intentionally does not merge with or overwrite a non-empty project.

Bun could not install dependencies

Confirm bun --version reports Bun 1.2 or later. You can also create with --no-install, enter the generated directory, and run bun install yourself.

X402_PAY_TO is invalid

Use a complete EVM address beginning with 0x. The server validates and checksum-normalizes the address at startup.

The paid endpoint returns 402

That is the expected response for a request without a payment signature. Run bun run test:challenge to validate the challenge, or use an x402 client to complete a paid request.

The challenge contains the wrong resource URL

Set PUBLIC_URL to the exact public HTTPS origin of the deployed server, without a path, query, or fragment.

Buyer/Client Guide

Send x402 payments to sellers with a TypeScript client.

Seller/Server Guide

Scaffold, configure, and deploy a Bun and Hono server that accepts x402 payments.

On this page

RequirementsCreate a serverInstall the command globallyCommand referenceWhat the server template includesGenerated scriptsConfigure the templateTroubleshootingThe target directory is not emptyBun could not install dependenciesX402_PAY_TO is invalidThe paid endpoint returns 402The challenge contains the wrong resource URL