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

@fourotwo/agent-sdk

v1.0.0

Published

fourotwo TypeScript SDK for automatic x402 payment handling

Downloads

37

Readme

@fourotwo/agent-sdk

  /$$$$$$                               /$$$$$$    /$$                            
 /$$__  $$                             /$$__  $$  | $$                            
| $$  \__//$$$$$$  /$$   /$$  /$$$$$$ | $$  \ $$ /$$$$$$   /$$  /$$  /$$  /$$$$$$ 
| $$$$   /$$__  $$| $$  | $$ /$$__  $$| $$  | $$|_  $$_/  | $$ | $$ | $$ /$$__  $$
| $$_/  | $$  \ $$| $$  | $$| $$  \__/| $$  | $$  | $$    | $$ | $$ | $$| $$  \ $$
| $$    | $$  | $$| $$  | $$| $$      | $$  | $$  | $$ /$$| $$ | $$ | $$| $$  | $$
| $$    |  $$$$$$/|  $$$$$$/| $$      |  $$$$$$/  |  $$$$/|  $$$$$/$$$$/|  $$$$$$/
|__/     \______/  \______/ |__/       \______/    \___/   \_____/\___/  \______/ 
                                                                                  

A drop-in fetch that pays for x402-gated APIs automatically.

When your agent calls an API that answers with HTTP 402 Payment Required, this SDK detects it, checks your spend budget, signs the payment with the agent's key, retries the request, and logs every payment transparently. You call fetch; it handles the money.

Part of fourotwo: the trust & settlement layer for agent payments.

Install

npm install @fourotwo/agent-sdk

Quickstart

import { fourotwoAgent } from '@fourotwo/agent-sdk';

const agent = new fourotwoAgent({
  privateKeyHex: process.env.FOUROTWO_PRIVATE_KEY, // signs locally, never sent
  budget: { dailyUsd: 10, perRequestUsd: 0.5 },    // optional spend caps
});

// behaves exactly like fetch but pays when it has to
const res = await agent.fetch('https://api.example.com/data/RE-NYC-001');
const data = await res.json();

The agent's DID is derived from your key automatically. Pass did explicitly only if you registered under a specific identity.

Generate an agent key

import { generateCasperKeypair } from '@fourotwo/agent-sdk';

const { privateKeyHex, publicKeyHex, did } = generateCasperKeypair();
// store privateKeyHex somewhere safe because it is the agent's identity + wallet

What happens on a 402

1. Your call gets a 402 + a PAYMENT-REQUIRED header
2. The SDK decodes the terms (amount, recipient, network, expiry, nonce)
3. It checks your budget — throws BudgetExceededError if over
4. It signs the canonical payment envelope with your key
5. It retries with PAYMENT-SIGNATURE + X-FOUROTWO-DID headers attached
6. On success it commits the spend and logs the payment to the ledger

Spend budgets

Budgets reject — they do not queue. If a payment would exceed a limit, the SDK throws BudgetExceededError before anything is signed, so a runaway loop can never drain the wallet. The daily counter resets at UTC midnight.

import { fourotwoAgent, BudgetExceededError } from '@fourotwo/agent-sdk';

const agent = new fourotwoAgent({
  privateKeyHex: process.env.FOUROTWO_PRIVATE_KEY,
  budget: { dailyUsd: 25, perRequestUsd: 1 },
});

try {
  await agent.fetch(url);
} catch (err) {
  if (err instanceof BudgetExceededError) {
    console.warn(`over budget (${err.scope}):`, err.message); // scope: 'daily' | 'per-request'
  }
}

Constructor options

| Option | Type | Notes | | --- | --- | --- | | privateKeyHex | string (required) | Agent signing key. Stays in your process. | | did | string | Defaults to the DID derived from the key. | | publicKeyHex | string | Override the derived public key (rarely needed). | | budget | SpendBudget | { dailyUsd?, perRequestUsd?, amountToUsd? }. | | logFilePath | string | Where to persist the transaction ledger. | | fetchImpl | typeof fetch | Custom fetch (tracing, tests, proxies). |

Transaction ledger

Every attempt is recorded locally — successes, failures, and budget rejections.

const log = agent.getTransactionLog();
// [{ did, amount, recipient, network, status, responseStatus, ... }]
// status: 'success' | 'failed' | 'budget_rejected'

Also exported

generateCasperKeypair, keypairFromPrivateKey, deriveAgentDid, signPayment, readPaymentRequiredHeader, TransactionLedger, and the error types BudgetExceededError, PaymentExpiredError, PaymentRequiredHeaderError, PaymentSigningError.

License & Terms of Service

Copyright (c) 2026. All rights reserved.

This repository is publicly visible for educational and review purposes only. By viewing this repository, you agree to the following terms:

  • No Duplication: You may not copy, duplicate, reproduce, or clone this source code, in whole or in part, outside of the GitHub platform.
  • No Modification or Distribution: You may not modify, distribute, publish, sub-license, or sell this code under any circumstances.
  • GitHub Platform Exception: In accordance with the GitHub Terms of Service, you are permitted to view and fork this repository strictly within GitHub for your own personal use.

Any unauthorized copying or use of this software constitutes copyright infringement.