Skip to content

@lelantos-org/sdk / x402 / BudgetLedger

Class: BudgetLedger โ€‹

Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:27

Constructors โ€‹

Constructor โ€‹

ts
new BudgetLedger(budget, allowHosts?): BudgetLedger;

Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:33

Parameters โ€‹

ParameterType
budgetBudget
allowHosts?readonly string[]

Returns โ€‹

BudgetLedger

Methods โ€‹

assertHostAllowed() โ€‹

ts
assertHostAllowed(url): void;

Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:35

Parameters โ€‹

ParameterType
urlstring

Returns โ€‹

void

Throws โ€‹

host-not-allowed


assertWithinLimits() โ€‹

ts
assertWithinLimits(
   amount, 
   asset, 
   resource?
): void;

Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:40

Parameters โ€‹

ParameterTypeDescription
amountCircuitAmountCircuit units for this asset.
assetAssetInfo-
resource?string-

Returns โ€‹

void

Throws โ€‹

per-request-limit or budget-exceeded


record() โ€‹

ts
record(amount, asset): void;

Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:58

Call only once a payment has been made.

Parameters โ€‹

ParameterType
amountbigint
assetbigint

Returns โ€‹

void


reserve() โ€‹

ts
reserve(
   amount, 
   asset, 
   resource?
): BudgetReservation;

Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:56

Check the limits and hold amount against them in one step.

Checking and recording separately is not enough: minting a payment takes seconds (a Groth16 prove, then a submit), and nothing held the ledger across that await โ€” so N concurrent payments all passed the check before any of them recorded, and the budget was enforced against a total that ignored every payment still in flight. With { total: "5" } and 1-unit payments, twenty concurrent calls all went through.

The reservation is synchronous and counts toward the limits until it is committed or released, so a concurrent caller sees it.

Parameters โ€‹

ParameterType
amountCircuitAmount
assetAssetInfo
resource?string

Returns โ€‹

BudgetReservation

Throws โ€‹

per-request-limit or budget-exceeded


spent() โ€‹

ts
spent(): Map<bigint, bigint>;

Defined in: @lelantos-org/sdk/dist/x402/budget.d.ts:60

Circuit units spent so far, keyed by asset id.

Returns โ€‹

Map<bigint, bigint>

Lelantosno cookies ๐Ÿช ยท no tracking ๐Ÿ‘๏ธ ยท no accounts ๐Ÿ‘คwalletexplorer4536080GitHub