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

@canopy-finance/x402-client

v0.1.0

Published

Buyer-side x402 client for the Canopy facilitator: build and post exact-permit2-v2 payments (EIP-712 Permit2 witness). Works in the browser and in Node. Zero runtime deps except viem (peer).

Readme

@canopy-finance/x402-client

Buyer-side x402 client for the Canopy facilitator. Build and post exact-permit2-v2 payments — an EIP-712 Permit2 witness that binds both the recipient and a stable serviceId into the payer's signature — without hand-rolling the typed data.

  • Works in the browser and in Node (uses fetch + globalThis.crypto only).
  • Zero runtime dependencies except viem (peer).
  • Signer-agnostic: pass any signTypedData (viem wallet, ethers, injected wallet…).
  • ESM + CJS + type declarations.

The EIP-712 shape here is the single source of truth shared with the facilitator's verifier, so buyer and verifier can never drift.

Install

npm install @canopy-finance/x402-client viem

The four-step buyer flow

import {
  getSupported,
  permit2ApprovalTx,
  createExactPermit2V2Payment,
  post,
} from "@canopy-finance/x402-client";
import { createWalletClient, custom } from "viem";

const url = "https://facilitator.canopyfinance.io";

// 1. Discover the facilitator's advertised kind (validates schemeVersion = 2).
const kind = await getSupported(url);

// 2. (once per payer) Approve Permit2 to move the asset on your behalf.
const wallet = createWalletClient({ account, transport: custom(window.ethereum) });
await wallet.writeContract(permit2ApprovalTx(kind));

// 3. Build a signed payment. `serviceId` comes from the resource's 402
//    response (paymentRequirements.extra.serviceId).
const body = await createExactPermit2V2Payment({
  chainId: 4663,
  kind,
  owner: account.address,
  payTo,          // the seller's recipient address
  amount: 10_000n, // atomic units (e.g. 0.01 USDG at 6 decimals)
  serviceId,       // bytes32 from the resource's 402
  signTypedData: (args) => wallet.signTypedData({ account, ...args }),
});

// 4. POST to /verify, then /settle.
const verified = await post(url, "verify", body);
if (verified.isValid !== true) throw new Error("verify failed");
const settled = await post(url, "settle", body /*, apiKey */);

Migration from v1 (exact-permit2)

The legacy exact-permit2 scheme is read-only. To integrate:

  1. Read serviceId from the resource's 402 (extra.serviceId).
  2. Call createExactPermit2V2Payment (the v1 creator createPermit2Payment now throws UnsupportedSchemeError).
  3. Target a facilitator advertising schemeVersion: 2 / payloadVersion: 2.

Exports

  • getSupported(url) — fetch + validate the exact-permit2-v2 kind.
  • permit2ApprovalTx(kind, amount?) — viem writeContract config for the one-time approval.
  • createExactPermit2V2Payment(params) — build a signed, ready-to-POST payment body.
  • post(url, "verify" | "settle", body, apiKey?) — POST helper.
  • Constants: PERMIT2_TYPES, WITNESS_TYPE_STRING, SUPPORTED_SCHEME, SUPPORTED_SCHEME_VERSION, SUPPORTED_PAYLOAD_VERSION.
  • Errors: UnsupportedSchemeError, UnsupportedSchemeVersionError, UnsupportedPayloadVersionError, MissingServiceIdError.

License

MIT