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

agent-budget-sdk

v2.0.0

Published

On-chain spending policy SDK for AI agents on Algorand x402

Readme

agent-budget-sdk

On-chain spending policy SDK for AI agents on Algorand x402.

One shared contract, many cards. Each card is a capped spending key: it can only call check_and_record_spend, and the contract just-in-time funds the card exactly the approved amount on each spend — so a compromised card key can never overspend. Live singleton: 764186085 (testnet).

Install

npm install agent-budget-sdk algosdk

Quick Start

import { AgentBudgetClient, makeBudgetWrappedFetch } from "agent-budget-sdk";
import { x402Client } from "@x402-avm/core/client";
import { ExactAvmScheme } from "@x402-avm/avm/exact/client";
import { toClientAvmSigner } from "@x402-avm/avm";

// 1. Construct the client with the CARD key (the spender)
const budget = await AgentBudgetClient.create({
  appId: 764186085n,
  signerMnemonic: process.env.AGENT_MNEMONIC!, // the card's 25-word mnemonic
});

// 2. Read live policy state
const status = await budget.getCardStatus();
console.log(`Remaining today: ${status.remaining} µALGO · balance: ${status.balance}`);

// 3. Wrap x402 fetch — budget checks happen on-chain before any payment is signed
const secretKey = /* base64 ed25519 secret for the card */;
const client = new x402Client().register("algorand:*", new ExactAvmScheme(toClientAvmSigner(secretKey)));
const budgetFetch = makeBudgetWrappedFetch({ budget, client });

try {
  const res = await budgetFetch("https://x402.goplausible.xyz/examples/weather");
} catch (e) {
  if (e instanceof BudgetRejectedError) console.log(`Blocked: ${e.reason}`);
}

API

AgentBudgetClient.create(opts)

| Option | Type | Description | |--------|------|-------------| | appId | bigint | The AgentBudget singleton app ID | | signerMnemonic | string | Mnemonic that signs — the card key to spend | | cardAddress? | string | Card to target for reads (defaults to the signer's address) | | algodServer? / algodPort? / algodToken? | — | Optional algod config (defaults to Nodely testnet) |

Client methods

| Method | Description | |--------|-------------| | checkAndRecordSpend(amount, server) | Card-signed: check policy, record spend, get JIT-funded. Returns true/false. | | getCardStatus() | { dailyLimit, spentToday, remaining, perTxLimit, balance, isPaused } | | getLifetimeStats() | { totalSpent, txCount, rejectedCount } | | isWhitelisted(server) | Whether a server is whitelisted for this card | | cardExists() | Whether the card exists on-chain |

Owner admin (create/deposit/withdraw/pause/limits/merchants) is done from the owner wallet — see scripts/onboard.ts for the create-card flow, or use the dashboard.

makeBudgetWrappedFetch(opts)

Returns a fetch-compatible function that:

  1. Preflights the URL for x402 pricing
  2. Calls checkAndRecordSpend on-chain
  3. Signs the x402 payment only if approved
  4. Throws BudgetRejectedError if rejected

BudgetRejectedError

  • reasonREJECTED:PAUSED, REJECTED:NOT_WHITELISTED, REJECTED:EXCEEDS_TX_LIMIT, REJECTED:EXCEEDS_DAILY_LIMIT, REJECTED:INSUFFICIENT_BALANCE
  • url, amount, server

Onboard a card + run the demo

cd agent-sdk
cp .env.example .env          # set AVM_MNEMONIC (owner, >=1 ALGO) + ALGORAND_TESTNET_APP_ID
pnpm install
pnpm run onboard              # owner creates a card + whitelists a host + funds the agent (one signature)
pnpm run demo                 # spends with the card key: approved, exhaust budget, rejected

License

MIT