npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alchemy/x402

v0.6.6

Published

CLI and library for Alchemy x402 authentication and payments

Downloads

840

Readme

@alchemy/x402

CLI and library for Alchemy x402 authentication and payments. Handles SIWE (Sign-In With Ethereum) and SIWS (Sign-In With Solana) auth, plus x402 per-request payments for the Alchemy agentic gateway.

Install

npm install @alchemy/x402
# or
yarn add @alchemy/x402
# or
pnpm add @alchemy/x402
# or
bun add @alchemy/x402

CLI

All commands accept an --architecture flag to switch between EVM and SVM (Solana). Defaults to evm.

EVM (Ethereum, Base, etc.)

# Generate a new EVM wallet
npx @alchemy/x402 wallet generate

# Import an existing wallet (accepts hex key or path to a key file)
npx @alchemy/x402 wallet import --private-key 0xac09...
npx @alchemy/x402 wallet import --private-key /path/to/keyfile

# Generate a SIWE token
npx @alchemy/x402 sign --private-key /path/to/keyfile --expires-after 1h

# Create an x402 payment from a PAYMENT-REQUIRED header
npx @alchemy/x402 pay --private-key /path/to/keyfile --payment-required <header>

SVM (Solana)

# Generate a new Solana wallet
npx @alchemy/x402 wallet generate --architecture svm

# Import an existing wallet (accepts base58 key, JSON byte array, or path to a key file)
npx @alchemy/x402 wallet import --private-key <base58-key> --architecture svm
npx @alchemy/x402 wallet import --private-key /path/to/keyfile --architecture svm

# Generate a SIWS token
npx @alchemy/x402 sign --private-key /path/to/keyfile --expires-after 1h --architecture svm

# Create an x402 payment from a PAYMENT-REQUIRED header
npx @alchemy/x402 pay --private-key /path/to/keyfile --payment-required <header> --architecture svm

Library

import {
  // EVM
  signSiwe,
  generateWallet,
  getWalletAddress,
  createPayment,
  buildX402Client,
  // SVM (Solana)
  signSiws,
  generateSolanaWallet,
  getSolanaWalletAddress,
  createSolanaPayment,
  buildSolanaX402Client,
  // Enum
  Architecture,
} from "@alchemy/x402";

Generate a wallet

// EVM
const evmWallet = generateWallet();
// { privateKey: "0x...", address: "0x..." }

const evmAddress = getWalletAddress("0x<private-key>");

// SVM (Solana)
const solWallet = generateSolanaWallet();
// { privateKey: "<base58>", address: "<base58>" }

const solAddress = getSolanaWalletAddress("<base58-secret-key>");

Sign an authentication token

// EVM — SIWE (Sign-In With Ethereum)
const siweToken = await signSiwe({
  privateKey: "0x<private-key>",
  expiresAfter: "1h", // optional, default "1h"
});

// SVM — SIWS (Sign-In With Solana)
const siwsToken = await signSiws({
  privateKey: "<base58-secret-key>",
  expiresAfter: "1h", // optional, default "1h"
});

Create an x402 payment

// EVM
const evmPayment = await createPayment({
  privateKey: "0x<private-key>",
  paymentRequiredHeader: "<base64-encoded PAYMENT-REQUIRED header>",
});

// SVM (Solana)
const solPayment = await createSolanaPayment({
  privateKey: "<base58-secret-key>",
  paymentRequiredHeader: "<base64-encoded PAYMENT-REQUIRED header>",
});

Use with @x402/fetch

For full request orchestration with automatic 402 payment handling, use buildX402Client with @x402/fetch:

import { buildX402Client, signSiwe } from "@alchemy/x402";
import { wrapFetchWithPayment } from "@x402/fetch";

const privateKey = "0x<private-key>";
const client = buildX402Client(privateKey);
const siweToken = await signSiwe({ privateKey });

// Wrap fetch with SIWE auth
const authedFetch: typeof fetch = async (input, init) => {
  const headers = new Headers(init?.headers);
  headers.set("Authorization", `SIWE ${siweToken}`);
  return fetch(input, { ...init, headers });
};

// Wrap with automatic x402 payment handling
const paymentFetch = wrapFetchWithPayment(authedFetch, client);

const response = await paymentFetch("https://x402.alchemy.com/...");

Private key input

EVM

All EVM commands and functions accept private keys as:

  • Hex string with 0x prefix: 0xac09...
  • Raw hex string: ac09...
  • File path: /path/to/keyfile

SVM (Solana)

All SVM commands and functions accept private keys as:

  • Base58-encoded 64-byte secret key
  • JSON byte array (Solana CLI format): [1, 2, 3, ...]
  • File path containing either format: /path/to/keyfile

For maintainers

See MAINTAINERS.md.