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

@meshgateway/x402-client

v0.1.0

Published

x402 payment client for the MeshGateway facilitator. Wrap fetch, sign the payment, get the resource.

Readme

@meshgateway/x402-client

Pay for x402 protected APIs with one wrapped fetch. Built for the MeshGateway facilitator and any merchant speaking x402 v2.

The client handles the whole flow: it makes the request, reads the 402 challenge, signs the payment with your wallet key, retries with the payment-signature header, and hands you the paid response.

Supported networks

| Network | Token | Scheme | | --- | --- | --- | | Robinhood Chain (eip155:4663) | USDG | permit2 | | Base (eip155:8453) | USDC | EIP-3009 | | Base Sepolia (eip155:84532) | USDC | EIP-3009 |

Install

npm install @meshgateway/x402-client viem

Quick start

import { privateKeyToAccount } from 'viem/accounts';
import { wrapFetch, decodePaymentResponse } from '@meshgateway/x402-client';

const account = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY);
const fetchWithPay = wrapFetch({ account });

const res = await fetchWithPay('https://pons.meshgateway.co/price?token=PONS');
const data = await res.json();

const settlement = decodePaymentResponse(res);
console.log(settlement?.transaction); // on-chain tx hash

Non 402 responses pass through untouched, so the wrapper is safe as a drop-in fetch replacement.

One-shot helper

import { payAndFetch } from '@meshgateway/x402-client';

const { response, settlement } = await payAndFetch(url, { account });

Options

wrapFetch({
  account,                       // viem local account (or any typed data signer)
  maxAmount: 100_000n,           // refuse prices above 0.10 USDC/USDG (default 1000000, one dollar)
  networks: ['robinhood', 'base'], // preference order when a merchant accepts several
  paymentSelector: (accepts) => accepts[0], // full control if you want it
});

Amounts are atomic token units. USDG and USDC both use 6 decimals.

One-time permit2 approval (Robinhood Chain)

Paying with USDG on Robinhood Chain uses permit2, which needs a one-time on-chain approval from your wallet. The wallet needs a small amount of gas for it.

import { ensurePermit2Approval } from '@meshgateway/x402-client';

await ensurePermit2Approval({ account, network: 'robinhood' });

Base USDC uses EIP-3009 and needs no approval and no gas at all.

Lower level pieces

Every step is exported if you want to compose your own flow:

  • decodeChallenge(response) reads the 402 challenge from the payment-required header or the JSON body.
  • buildPayment(signer, requirements) signs one accepts entry and returns the payment payload.
  • buildPaymentHeader(challenge, options) picks an entry, signs it, and returns the base64 header value.
  • decodePaymentResponse(response) reads the settlement receipt (payment-response or x-payment-response).
  • NETWORKS, PERMIT2_ADDRESS, X402_PERMIT2_PROXY, header name constants.

Facilitator

Merchants verify and settle these payments through the MeshGateway facilitator at https://facilitator.meshgateway.co. If you are building the server side, see @meshgateway/x402-server.

License

MIT