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

@neargate/sdk

v0.1.0

Published

Pay HTTP 402 (x402) APIs in native NEAR from Node: read the NearGate registry, pay a gateway's invoice from a deposit, an escrow or gasless, and get the response.

Readme

@neargate/sdk — pay x402 APIs in native NEAR

The NearGate client SDK for Node. Read the on-chain neargate-registry catalog, pay a gateway's HTTP 402 invoice in native NEAR and get the response, with the same code the neargate CLI runs. Three ways to pay:

  • deposit (default): call the registry's pay with price + the 0.002 NEAR storage fee attached;
  • escrow: pay_from_escrow debits a balance you prepaid, so a restricted agent key can pay;
  • gasless: sign that pay_from_escrow as a NEP-366 delegate and let the gateway relay it and pay the gas.

The defaults target the live deployment on NEAR testnet: the registry neargate-app-registry.testnet and the gateway https://neargate-gateway-production.up.railway.app.

npm install @neargate/sdk

Node 22.22.2 or later, ESM only.

Read the catalog (no key)

import { createNearGateChain, formatNear } from '@neargate/sdk';

// Live mode on NEAR testnet and the deployed registry. Options: mode, network, rpcUrl, registryId.
const chain = createNearGateChain();

for (const s of await chain.listServices()) {
  const score = await chain.getScore(s.id);
  console.log(s.id, s.name, formatNear(s.priceYocto), `${score.successCalls}/${score.totalCalls}`, s.endpointUrl);
}

Pay for a call

import { createAgentGateClient, createNearGateChain, nearToYocto } from '@neargate/sdk';

const chain = createNearGateChain();
const client = createAgentGateClient({
  chain,
  // The key is read from ~/.near-credentials/testnet/you.testnet.json; or pass keyPath / secretKey.
  signer: { kind: 'near', accountId: 'you.testnet' },
  maxYocto: nearToYocto('0.02'), // refuse any invoice above 0.02 NEAR in total
  expectedServiceId: 1,
});

const res = await client.fetchPaid('https://neargate-gateway-production.up.railway.app/svc/1');
console.log(res.status, res.txHash, res.body);

fetchPaid requests the URL, validates the 402 invoice (network, registry, service, budget), pays it, retries with the X-PAYMENT proof and returns the response. Every refusal before paying throws an AgentGateError with a stable code (BUDGET_EXCEEDED, NETWORK_MISMATCH, REGISTRY_MISMATCH, FORBIDDEN_HOST, …).

Never pay twice for one call. If the payment went through but the gateway did not serve the call, fetchPaid throws PaidNotServedError (PAID_NOT_SERVED), or GaslessNotServedError on the gasless rail, carrying the proof to present again. Do not pay a fresh invoice for it.

From an escrow, or gasless

const signer = { kind: 'near', accountId: 'you.testnet' } as const;
const maxYocto = nearToYocto('0.02');
// The first deposit keeps 0.002 NEAR as the escrow's storage fee.
await chain.depositEscrow(nearToYocto('1'), signer);

const escrowClient = createAgentGateClient({ chain, signer, maxYocto, payFrom: 'escrow' });
const gaslessClient = createAgentGateClient({ chain, signer, maxYocto, payFrom: 'escrow', gasless: true });

chain.escrowOf(accountId) reads the balance. A gasless call needs a gateway that offers a relayer (extra.relayer in its 402); the hosted gateway does.

What is in the package

One bundled ES module with its types:

  • the paying client: createAgentGateClient, PaidNotServedError, GaslessNotServedError, parsePaymentRequired, fetchReceipt, waitForReceipt;
  • the chain clients: createNearGateChain (from options; { mode: 'mock' } uses the offline devnet of the repository's npm run dev), createChainClient (from a full loadConfig configuration), LiveNearClient and MockChainHttpClient;
  • the shared vocabulary: loadConfig, the hosted defaults (DEFAULT_REGISTRY_CONTRACT_ID, DEFAULT_GATEWAY_URL), NEAR amounts (nearToYocto, formatNear), the x402 types and AgentGateError.

The protocol, every error code and the security model are documented at https://neargate-dashboard-production.up.railway.app/docs. Source: https://github.com/nnovida/neargate.

License

MIT