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

trytollgate

v0.2.0

Published

Wraps fetch so an HTTP 402 payment challenge is checked by a Tollgate gateway before anything is signed or paid. For AI agents.

Readme

trytollgate (the Tollgate SDK)

Wraps fetch so an HTTP 402 payment challenge is routed through the Tollgate gateway. Runs in the agent's process, which is the untrusted zone: it holds an agent token, never a key.

Install

npm install trytollgate

It has one runtime dependency, viem. In this repository it is the workspace package packages/sdk.

Protect an agent in 9 lines

import { createTollgate, httpRpcRail } from 'trytollgate'

const tollgate = createTollgate({
  gatewayUrl: 'http://127.0.0.1:8787', agentToken: process.env.TOLLGATE_AGENT_TOKEN!, mandateId: 'mnd_1',
  payer: '0xYourSignerPublicAddress', rail: httpRpcRail({ 'eip155:42161': 'https://arb1.arbitrum.io/rpc' }),
})
const res = await tollgate.fetch('https://merchant.example.com/data') // a 402 is handled for you

What tollgate.fetch does

agent ── fetch ──► merchant ──► 402 + challenge
                                   │
                                   ▼
            gateway /v1/authorize ── DENY ──► throws PaymentDenied (names the check that stopped it)
                       │            └ NEEDS_APPROVAL ─► throws ApprovalRequired (or waits, if you ask it to)
                     ALLOW
                       ▼
     rail.txParams ─► gateway /v1/payments/:id/sign ─► (signer signs) ─► rail.send ─► chain
                       ▼
        retry ONCE with header  x-payment-proof: {challengeId, txHash, depositAddress}
  • Never pays twice for one call. If the merchant still says 402 after being paid, that 402 is handed back, not followed.
  • Never pays a 402 it cannot read. It is returned untouched.
  • Your agent token goes to the gateway and nowhere else. The merchant never sees it.
  • Errors say whether money may have moved. PaymentFailed.mayHavePaid is false before a signed transaction is handed to the network and true after.

| Error | Meaning | Money moved? | | --- | --- | --- | | PaymentDenied | The gateway refused. failedCheck names the check (for example C05: the payee changed). | No | | ApprovalRequired | A person must approve first. decisionId identifies it. | No | | PaymentFailed (stage: 'params' or 'sign') | Allowed, but could not be prepared or signed. | No | | PaymentFailed (stage: 'broadcast') | Signed, but sending was not confirmed. | Maybe | | GatewayError | The gateway could not be used (unreachable, wrong token). | No |

To wait for a person instead of throwing, pass approval: { wait: true }: the SDK asks again about the same challenge (which returns the same pending decision, not a second one) until it is approved, rejected, or the timeout passes.

Stated limits

  • The 402 format here is Tollgate's own: the challenge in the response body as JSON (or { "challenge": {...} }), and the proof in an x-payment-proof header. It is what apps/mock-merchants speaks. Real MPP / x402 headers are a separate adapter, to be added once the payment path is chosen.
  • A request body must be replayable (a string or buffer, not a one-shot stream), because it is sent again on the retry.
  • httpRpcRail reads a nonce and fees over public JSON-RPC and broadcasts the signed transaction. Using it with a funded key spends real money; that is always the owner's decision.

Paying from NEAR (0.2.0+)

nearRpcRail pays from a NEAR account instead of an EVM chain. The gateway's signer must be configured for NEAR (see the repository's getting-started guide); publicKey is the signer's PUBLIC key from its /healthz.

import { createTollgate, nearRpcRail } from 'trytollgate'

const tollgate = createTollgate({
  gatewayUrl: 'http://127.0.0.1:8787', agentToken: process.env.TOLLGATE_AGENT_TOKEN!, mandateId: 'mnd_1',
  payer: 'your-agent.near',
  rail: nearRpcRail({ rpcUrl: 'https://rpc.mainnet.near.org', publicKey: 'ed25519:...' }),
})

It reads the access key's nonce and a block hash in one RPC call, and broadcasts the signed bytes with send_tx. Tested against a fake RPC; not yet run with a funded NEAR account.