Budget.create
Cap total spending across payments
Creates a shared spending budget for charge payments.
Usage
import { , , } from 'mppx/client'
import { } from 'viem/accounts'
const = .({ : { : 'USD', : '5' } })
const = .({
: ,
: [({ : ('0x...') })],
: false,
})
await .('https://api.example.com/paid')
.(.())
{ currency: 'USD', value: '4.99' }Reservations are synchronous, so concurrent requests share the same cap. mppx commits a reservation when it creates a Credential and releases it if funding or Credential creation fails. A request that times out after Credential creation counts as spent; reconcile its payment before retrying.
Use an asset total to cap one token in atomic units:
const budget = Budget.create({
total: {
amount: 5_000_000n,
asset: '0x20c0000000000000000000000000000000000000', // pathUSD on Tempo
network: 'eip155:42431',
},
})Return type
type Budget = ((plan: Spend.Plan, context?: Spend.Context) => Spend.Authorization) & {
readonly total: Spend.Money | Spend.AssetLimit
remaining(): Spend.Money | Spend.AssetLimit
reserved(): Spend.Money | Spend.AssetLimit
spent(): Spend.Money | Spend.AssetLimit
}Parameters
total
- Type:
Spend.Money | Spend.AssetLimit
The shared cap. Use { currency, value } for a reference currency or { amount, asset, network } for an asset's atomic units. Currency budgets trust only tokens configured by the client and Tempo's built-in stablecoins. Payments in other assets fail with PaymentLimitExceededError.