New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

z402

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

z402

Zero Trust x402 protocol

latest
Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

z402

Express middleware for HTTP 402-based Solana payments.

Install

npm install z402

Basic Example (Express)

import express from "express";
import { createPaymentContext } from "z402/express";
import { Connection, clusterApiUrl } from "@solana/web3.js";

const app = express();

(async () => {
  const z402 = await createPaymentContext({
    connection: new Connection(clusterApiUrl("devnet")),
  });

  app.get("/premium", z402.route("DEST_WALLET", "1000000"), (req, res) => 
    res.send({"message": "Paid content unlocked!", payment: res.locals.payment})
  );

  app.listen(3000);
})();

Server (Hono)

import { Hono } from "hono";
import { createPaymentContext } from "z402/hono";
import { Connection } from "@solana/web3.js";

const app = new Hono();

(async () => {
  const z402 = await createPaymentContext({connection: new Connection("https://api.devnet.solana.com")});

  app.get("/paid", z402.route("DestinationWalletPubkeyHere", "1000000"), (c) => 
      c.json({"message": "Paid content unlocked!", payment: c.get("payment")})
  );
})();

Persistence (Optional)

To enable crash-proof idempotence:

import { initSqliteDb } from "z402-storage-sqlite";

const z402 = await createPaymentContext({
  connection,
  db: initSqliteDb("./payments.db"),
});

Status codes

  • 200: finalized payment,
    • for express res.locals.payment contains tx details.
    • for hono c.get("payment") contains tx details.
    • signature: tx signature
    • signer: payer public key
    • destination: destination public key
    • amount: amount in lamports or raw token units
    • mint: null for SOL, mint address for SPL
  • 202: pending (timeout reached). Retry the same request.
  • 400: invalid tx / already pending.
  • 500: final error on-chain (rebuild a new tx)

Keywords

solana

FAQs

Package last updated on 11 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts