Skip to content

@lelantos-org/sdk / x402 / BudgetLedger

Class: BudgetLedger ​

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

Enforces Budget and the host allowlist, and tracks spend. One ledger per x402() call; totals cover the payer's lifetime, not the process's.

Constructors ​

Constructor ​

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

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

Parameters ​

ParameterType
budgetBudget
allowHosts?readonly string[]

Returns ​

BudgetLedger

Methods ​

assertHostAllowed() ​

ts
assertHostAllowed(url): void;

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

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:38

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:51

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:49

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

Minting a payment spans a Groth16 prove and a submit, so checking and recording separately would let concurrent payments all pass the check before any is recorded. The hold counts toward the limits until it is committed or released.

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:53

Circuit units spent so far, keyed by asset id.

Returns ​

Map<bigint, bigint>