---
id: UC0031
title: "Fee sponsor budget monitor"
url: https://carbium.sh/library/usecase/fee-sponsor-budget-monitor
collection: Use cases
category: Wallet products
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Fee sponsor budget monitor

Sponsoring gas for users turns one wallet balance into your product's uptime. Measure its spendable lamports, its recent fee burn and the hours of runway left, with a read-only Node script and the call costs of checking.

## The budget is one balance

A gasless product lets a user send a transaction without holding SOL. A server-held wallet, the fee payer, is the first account key in the message and pays for it. What it pays is the full fee the network charges: 5000 lamports per signature plus any priority fee the transaction sets ([priority fee per compute unit](https://carbium.sh/library/howsolana/priority-fee-per-compute-unit)).

The whole sponsorship budget is therefore a lamport balance on one account. When it runs out, every sponsored transaction fails at once, and users see a wallet that worked yesterday and refuses today. Nothing on chain warns you ahead of time, so the warning has to come from you: the balance, how fast it falls, and the hours left at that speed.

Two details change the arithmetic. A failed transaction still pays its fee, so a burst of failures drains the wallet as fast as a burst of successes. And the account cannot be spent to the last lamport, because a system account must stay at or above the rent-exempt minimum for its size. The spendable part is the balance minus that minimum.

## Three numbers to watch

- Spendable balance: `getBalance` minus `getMinimumBalanceForRentExemption` for a zero-data account.
- Burn rate: lamports of fees per hour, taken from the newest transactions the wallet paid for. The script drops the oldest fee from the sum, because that transaction happened before the span it measures.
- Runway: spendable divided by burn rate, in hours. The script alerts below 24 hours by default and reads `RUNWAY_HOURS` if you set it.

Only transactions where the sponsor is the first account key count. A transaction that lists the wallet as a second signer takes nothing from it in fees, and an address list from `getSignaturesForAddress` includes those as well as the ones it paid for.

Runway in hours is a coarse number on purpose. A top-up job and a human both need time to act, so the useful alert is a runway of a day or two, and an hour-level value of that size changes slowly enough to poll every few minutes.

## The monitor in one file

The script takes the sponsor address as its first argument. With no argument it reads the newest few signatures of a busy program and uses the first fee payer it can look up, so it runs anywhere. It builds one client on `https://services.carbium.sh` with the key in the `x-api-key` header ([endpoints](https://carbium.sh/docs#endpoints), [auth](https://carbium.sh/docs#auth)), reads the balance, the rent floor and the newest signatures in parallel, then looks up each transaction.

`main.ts` (run: `CARBIUM_KEY=$CARBIUM_KEY node main.ts <sponsor-address>`)

```ts
// UC0031 · Fee sponsor budget monitor
// https://carbium.sh/library/usecase/fee-sponsor-budget-monitor
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Read-only: how many hours a fee-sponsor wallet can keep paying fees at its recent burn rate.
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, type Signature } from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({
  url: process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh",
  headers: { "x-api-key": key },
}));
const SAMPLE = Math.min(Number(process.env.SAMPLE ?? 10), 15);
const MIN_HOURS = Number(process.env.RUNWAY_HOURS ?? 24);
const BUSY_PROGRAM = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
const cfg = { maxSupportedTransactionVersion: 1, encoding: "json" } as const;

// Fee payer (first account key) and total fee of one transaction; null when the ledger no longer has it.
const payerOf = async (signature: Signature) => {
  const tx = await rpc.getTransaction(signature, cfg).send();
  return tx ? { payer: String(tx.transaction.message.accountKeys[0]), fee: Number(tx.meta?.fee ?? 0) } : null;
};

let sponsor = process.argv[2] ?? "";
if (!sponsor) {
  const recent = await rpc.getSignaturesForAddress(address(BUSY_PROGRAM), { limit: 5 }).send().catch(() => []);
  const found = await Promise.allSettled(recent.map((s) => payerOf(s.signature)));
  sponsor = found.flatMap((f) => (f.status === "fulfilled" && f.value ? [f.value.payer] : []))[0] ?? "";
  if (!sponsor) { console.error("No fee payer found; pass an address."); process.exit(1); }
  console.log(`no address given, using a recent fee payer: ${sponsor}`);
}

const [bal, floor, sigs] = await Promise.allSettled([
  rpc.getBalance(address(sponsor)).send(),
  rpc.getMinimumBalanceForRentExemption(0n).send(),
  rpc.getSignaturesForAddress(address(sponsor), { limit: SAMPLE }).send(),
]);
for (const r of [bal, floor, sigs]) if (r.status === "rejected") console.error("call failed:", String(r.reason));
if (bal.status !== "fulfilled") process.exit(1);
const spendable = Number(bal.value.value) - (floor.status === "fulfilled" ? Number(floor.value) : 0);

const list = sigs.status === "fulfilled" ? sigs.value : [];
const done = await Promise.allSettled(list.map((s) =>
  payerOf(s.signature).then((p) => (p && p.payer === sponsor && s.blockTime != null ? { t: Number(s.blockTime), fee: p.fee } : null))));
const paid = done.flatMap((d) => (d.status === "fulfilled" && d.value ? [d.value] : [])).sort((a, b) => b.t - a.t);
const failed = done.filter((d) => d.status === "rejected").length;

console.log(`sponsor ${sponsor}`);
console.log(`balance ${bal.value.value} lamports, spendable ${spendable}`);
console.log(`sampled ${list.length} signatures, ${paid.length} paid by the sponsor, ${failed} lookups failed`);
const hours = paid.length > 1 ? (paid[0]!.t - paid[paid.length - 1]!.t) / 3600 : 0;
if (hours <= 0) {
  console.log("Need two fee-paying transactions at different times for a burn rate.");
} else {
  const perHour = (paid.reduce((n, p) => n + p.fee, 0) - paid[paid.length - 1]!.fee) / hours;
  const runway = spendable / perHour;
  console.log(`burn ${perHour.toFixed(0)} lamports/hour, runway ${runway.toFixed(1)} hours`);
  if (runway < MIN_HOURS) console.log(`ALERT runway under ${MIN_HOURS} hours for ${sponsor}`);
}
```

Each call is settled on its own, so one failed lookup shows up as a count and the rest of the sample still produces a number. `getTransaction` passes `maxSupportedTransactionVersion: 1`, which keeps v1 transactions from answering [-32015](https://carbium.sh/docs#errors). Calls leave commitment out, and @solana/kit fills in confirmed, so the balance and the transactions are read at confirmed.

The output is four lines: the address, the balance with its spendable part, how many signatures were sampled and how many the sponsor paid for, and the burn rate with the runway. The last line starts with ALERT when the runway is under the threshold. Wire that line to your pager or to the job that tops the wallet up.

## What a check costs

The sample is the expensive part. Every transaction lookup is a [50-cell call](https://carbium.sh/docs#rpc), and the address listing is another.

| Call | Cells | Free req/s | Dev req/s | Business req/s | Pro req/s |
|---|---|---|---|---|---|
| getSignaturesForAddress | 50 | 0.24 | 1.2 | 100 | 500 |
| getTransaction | 50 | 0.24 | 1.2 | 5 | 25 |

A default run is one listing and ten lookups, 550 cells across those two classes. A class [absorbs bursts](https://carbium.sh/docs#limits) up to 1,024 cells or one second of its rate, whichever is larger, and a poll of 15 lookups is 750 cells in the lookup class, which fits inside one burst. Credits meter this RPC work as well, and an account's keys share both the rates and the credits.

Run it from a timer every few minutes. To cut the cost further, keep the signatures you have already priced in your own store and pass the newest as `until`, so each poll prices only new transactions and keeps a running list for the burn window.

## Reacting sooner with a log subscription

Polling is enough for a runway that is measured in hours. If you want a reaction per sponsored transaction, subscribe over the [WebSocket](https://carbium.sh/docs#websocket). A sponsor is a plain SOL wallet, and `accountSubscribe` sends nothing for a plain SOL wallet, so use `logsSubscribe` with a mentions filter on its address and call `getBalance` after each notification.

A mentions subscription opens at 25 credits and then costs 20 credits per MiB sent. A busy sponsor streams every transaction it touches, so the bill follows your traffic. Keep the subscription for the days you run close to the floor, and poll the rest of the time.

## Where it ends

- The burn rate comes from a sample of at most 15 transactions, so a short burst of traffic inflates it and a quiet hour deflates it. Compare two windows and alert on the worse one.
- getSignaturesForAddress reads from an address index that keeps up to 30 days, and its pages reach below the validator's ledger floor, so `getTransaction` can answer null for an older signature it lists. The script skips those and samples the newest.
- The monitor measures fees. A sponsor that also funds rent for accounts it creates, or pays fees in a token, spends more than the number shows. Add those flows from your own records.
- It reads one wallet. A product with a pool of fee payers runs it once per wallet and alerts on the pool total as well as on each member.
- It signs and sends nothing. Topping the wallet up is a separate job with its own key and its own approval path.
- A balance read and a transaction read can sit a slot or two apart at confirmed. For a runway in hours that gap does not matter.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The output says it needs two fee-paying transactions and prints no runway. | The sample held fewer than two transactions the sponsor paid for, so there is no span to divide by. Raise `SAMPLE` up to 15 or poll later. An idle sponsor has no burn to project. |
| getTransaction answers null for a signature the listing returned. | The listing reaches below the validator's ledger floor, so an older signature can have no transaction to read. Skip it and sample the newest signatures. |
| getTransaction answers -32015 for a recent signature. | Pass `maxSupportedTransactionVersion: 1` in the call config. Left out or 0, the call refuses a v1 transaction. See [Transaction version error -32015](https://carbium.sh/library/howsolana/transaction-version-error-32015). |
| The alert fires on every poll while the wallet sits below the threshold. | Keep the last alert time and stay quiet for a set period, then page again if the runway keeps falling. |
| The spendable figure is lower than the balance in a wallet app. | The script subtracts the rent-exempt minimum for a zero-data account. That amount stays on the account and cannot pay fees. |
| Several lookups fail at once during a poll. | The sample went over a rate. Lower `SAMPLE`, poll less often, or cache priced signatures and look up only new ones. |

## Questions

### Does a failed sponsored transaction cost the wallet?

Yes. A transaction that lands and fails still charges its fee to the fee payer. The script counts failed transactions in the burn rate for that reason.

### How often should the monitor run?

Runway is measured in hours, so every few minutes is enough. Each run with the default sample is 550 cells over the two lookup classes, and a tight loop would spend rate you need elsewhere.

### How do I watch a pool of fee payers?

Run the script once per wallet with each address as the argument, then add up the spendable balances and the burn rates for a pool runway. Alert on the pool and on each wallet, because one drained payer fails the sends routed to it.

### Can it tell me when a user hits a limit on my sponsorship?

No. Per-user caps live in your own service, and this script watches only the shared wallet's balance and burn. Pair it with a counter per user in your database, as in [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts).

## Related

- [Priority fee per compute unit](https://carbium.sh/library/howsolana/priority-fee-per-compute-unit) (How to use Solana, HS0015)
- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
- [carbium.sh/docs#migrate](https://carbium.sh/docs#migrate)
