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

x402-casper

v0.1.0

Published

HTTP-402 micropayments settled by a real Casper transfer — payer-bound, single-use, zero dependencies.

Readme

x402-casper

HTTP-402 micropayments settled by a real Casper transfer. Payer-bound, single-use, fails closed, zero runtime dependencies.

This is the payment rail the Hunch on Casper agent economy runs on, extracted so any Casper project can charge for an HTTP endpoint. The package compiles from the same source the live app serves, so the rail you install is the rail we dogfood.

Install

npm i x402-casper

The exchange

  1. A client requests a paid resource with no proof.
  2. The server answers 402 with a challenge: what to pay, where, and a nonce bound to this payer and these parameters.
  3. The client sends a native CSPR transfer to payTo from the account named in payer.
  4. The client retries with X-PAYMENT: base64(json({ scheme, deployHash, nonce })).
  5. The server reads that transaction from a Casper node and verifies four things at once.

Server

import { requirePayment, createSettlementRegistry, encodePaymentResponse } from "x402-casper";

const registry = createSettlementRegistry(); // durable store in production — see SPEC.md

export async function POST(req: Request) {
  const gate = await requirePayment(req, {
    payment,                       // your PaymentPort
    resource: "/api/report",
    quote: { marketId: "report", outcomeKey: "one", amountMotes: "2500000000", payer },
    registry,
  });
  if (!gate.paid) return Response.json(gate.body, { status: gate.status });

  return Response.json(await buildReport(), {
    headers: { "x-payment-response": encodePaymentResponse(gate.proof.deployHash) },
  });
}

requirePayment returns data, not a Response, so it composes with Next route handlers, Express, Hono, or a bare fetch server without any of them becoming a dependency.

Verifying a payment yourself

The verifier is a pure function over a node-RPC transaction lookup — no network, no key, no framework. It reads both the Casper 2.0 info_get_transaction shape and the legacy info_get_deploy one.

import { verifyTransferResult } from "x402-casper";

const json = await (await fetch(nodeRpcUrl, { method: "POST", body: rpcBody })).json();
const paid = verifyTransferResult(json, requirement, proof); // boolean, never throws

It returns true only when all four hold:

| Check | Why it matters | |---|---| | The transaction executed successfully | A queued or reverted transfer moved nothing | | Its initiator is the requirement's payer | Without this, any hash on chain is a bearer token | | It moved at least amountMotes | — | | It landed on payTo | — |

The second one is the check most implementations miss, and the one that matters most.

What it does not do

Native CSPR only — so the chainspec's 2.5 CSPR native-transfer minimum is a hard floor on a single payment. No CEP-18, no escrow, no refunds. It answers one question: did this payer really pay this much to this account?

Replay protection

Burn the settlement id (the transaction hash), not the nonce. A challenge for a resource is stable and may be paid many times; each payment settles exactly once. createSettlementRegistry is the in-memory reference — correct for one process, not for serverless, where N cold instances each hold their own empty set and the same proof buys N times. Back it with a durable store there.

Wire format

SPEC.md describes the challenge, the proof header and the verification rules precisely enough to reimplement in another language.

License

MIT