x402-npm
v0.1.3
Published
npm CLI wrapper with x402 payment support for monetized packages
Maintainers
Readme
x402-npm
A drop-in npm CLI replacement with built-in x402 payment support for monetized packages.
Installation
npm install -g x402-npmOverview
x402-npm is a drop-in replacement for npm that enables seamless micropayments for npm packages using the x402 payment protocol. It works with the x402 npm registry to allow developers to:
- Install any npm package - works with all packages from npmjs.org
- Install paid packages with automatic USDC payments on Base network
- Manage a crypto wallet for package payments
- Authenticate via email verification
All standard npm commands work exactly as expected. The x402 registry proxies to npmjs.org, so you get full access to the entire npm ecosystem plus paid x402 packages.
Quick Start
# 1. Login (creates a wallet automatically)
x402-npm login
# 2. Fund your wallet with USDC
x402-npm wallet fund
# 3. Install packages (paid packages require confirmation)
x402-npm install some-paid-packageCommands
x402-npm login
Authenticate with the x402 registry using email verification.
x402-npm loginFlow:
- Enter your email address
- Receive a 6-digit verification code via email
- Enter the code to complete login
On first login:
- A new user account is created
- A custodial wallet is automatically provisioned on Base network
- Credentials are saved locally in
~/.x402-npm/session.json
Example:
$ x402-npm login
Enter your email: [email protected]
Sending verification code to [email protected]...
Verification code sent!
Enter verification code: 123456
Verifying...
==================================================
Logged in successfully!
==================================================
User: [email protected]
Wallet: 0x1234...abcd
Network: base
Tip: Run 'x402-npm wallet fund' to add USDC to your walletx402-npm logout
Sign out from the x402 registry and clear local session data.
x402-npm logoutExample:
$ x402-npm logout
Logged out from [email protected]x402-npm whoami
Display current logged-in user and wallet information.
x402-npm whoamiExample:
$ x402-npm whoami
User: [email protected]
Username: developer_abc123
Wallet: 0x1234...abcd
Network: base
Session created: 12/4/2025, 3:45:00 PMx402-npm install [packages...]
Install packages with x402 payment support.
x402-npm install <package-name> [options]Aliases: x402-npm i
Options:
| Option | Description |
|--------|-------------|
| -D, --save-dev | Save as dev dependency |
| -g, --global | Install globally |
| --save-exact | Save exact version |
| -y, --yes | Auto-confirm payment (skip confirmation prompt) |
Behavior:
- Checks if packages require payment
- Shows pricing breakdown for paid packages
- Prompts for payment confirmation (unless
--yesis used) - Signs payment using your wallet
- Downloads packages after payment verification
- Runs standard
npm install
Example (paid package):
$ x402-npm install premium-lib
Checking package prices...
Packages requiring payment:
premium-lib: $0.05 USDC
Total: $0.05 USDC
Logged in as: [email protected]
Wallet: 0x1234...abcd
Proceed with payment of $0.05 USDC? (y/N) y
Processing payments and downloading packages...
Processing premium-lib...
Signing payment for premium-lib...
Downloading premium-lib...
Paid for premium-lib
Running npm install...Example (free package from x402 registry):
$ x402-npm install lodash
Checking package prices...
Free packages:
lodash
Running npm install...Example (regular npm package - no login required):
$ x402-npm install express react typescript
Checking package prices...
Free packages:
express
react
typescript
Running npm install...Note: Free packages and standard npm packages don't require login. Only paid x402 packages require authentication.
Example (auto-confirm):
$ x402-npm install premium-lib --yes
Checking package prices...
Packages requiring payment:
premium-lib: $0.05 USDC
Total: $0.05 USDC
Auto-confirming payment of $0.05 USDC...
...x402-npm wallet
Display wallet information and balances.
x402-npm walletExample:
$ x402-npm wallet
Wallet Info
===========
Address: 0x1234...abcd
Network: base
Fetching balances...
Balances:
USDC: $10.50
ETH: 0.001 ETH
Tip: Run 'x402-npm wallet fund' to add USDC to your walletx402-npm wallet fund
Open Coinbase Onramp in your browser to purchase USDC and fund your wallet.
x402-npm wallet fundExample:
$ x402-npm wallet fund
Generating secure onramp session...
Wallet: 0x1234...abcd
Opening Coinbase Onramp in your browser...
Onramp opened in browser. Complete the purchase to fund your wallet.Note: If the browser fails to open, you can manually send USDC (on Base network) to your wallet address.
x402-npm wallet export
Display wallet export information.
x402-npm wallet exportExample:
$ x402-npm wallet export
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WARNING: This wallet is managed by Coinbase Developer Platform.
Private keys are securely stored server-side and are not
directly exportable from the CLI.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Wallet Address: 0x1234...abcd
Network: base
To export your private key, visit the CDP dashboard at:
https://portal.cdp.coinbase.comPassthrough Commands
All other npm commands are passed through to npm directly:
# These work exactly like regular npm
x402-npm publish
x402-npm init
x402-npm run build
x402-npm test
x402-npm update
x402-npm uninstall package-name
# ... any other npm commandConfiguration
Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| X402_REGISTRY | Custom registry URL | https://api.x402npmregistry.com |
Example:
export X402_REGISTRY=https://your-registry.example.com
x402-npm loginSession Storage
Session data is stored in ~/.x402-npm/session.json and includes:
- Authentication token
- User information
- Wallet address and network
- NPM token for registry access
How Payments Work
x402 Protocol: When you request a paid package, the registry returns HTTP 402 (Payment Required) with payment details.
Server-Side Signing: Your wallet is custodial (managed by Coinbase Developer Platform). Payment signatures are generated server-side using your session token.
USDC on Base: Payments are made in USDC on the Base network (Coinbase's L2). Transactions are fast and have minimal gas fees.
Atomic Downloads: Payment is verified before the package tarball is served. No payment = no package.
Publishing Paid Packages
To publish a package to the x402 registry:
# 1. Login to get your auth token
x402-npm login
# 2. Set the x402 registry as your npm registry
npm config set registry https://api.x402npmregistry.com
# 3. Set your auth token (get this from x402-npm whoami or ~/.x402-npm/session.json)
npm config set //api.x402npmregistry.com/:_authToken "YOUR_NPM_TOKEN"
# 4. Publish your package
npm publish
# 5. Set pricing via the web UI
# Visit: https://www.x402npmregistry.comTo get your auth token:
# Option 1: Check your session file
cat ~/.x402-npm/session.json | grep npmToken
# Option 2: The token is shown after login
x402-npm loginDefault price for new packages is $0.01 USDC. You can adjust pricing in the web dashboard at www.x402npmregistry.com.
Troubleshooting
"Not logged in" error
Run x402-npm login to authenticate.
"Insufficient balance" error
Run x402-npm wallet fund to add USDC to your wallet.
Package not found
The x402 registry proxies to npmjs.org for packages not published directly. If a package isn't found, it may be a network issue.
Session expired
Run x402-npm logout then x402-npm login to refresh your session.
License
MIT
