What Are Spending Policies?
Spending policies let wallet owners set dollar-denominated caps on what a session key can spend. The CHIPI wallet contract enforces these limits automatically during transaction execution — no backend or middleware needed. Limits are enforced on ERC-20 operations:transfer, approve, increase_allowance.
Spending policies require CHIPI v33 wallets. v29 wallets do not have these entrypoints. See Wallet Upgrades to upgrade.
When to Use Spending Policies
How It Works
Configuration
A spending policy has three parameters:
The contract also tracks:
If no policy is set (maxPerWindow is 0), the session has no spending limits. All ERC-20 operations are allowed without caps.
TypeScript Backend
React / Next.js
TheuseChipiSession hook includes spending policy actions:
The React hook automatically injects the current session’s
sessionPublicKey. You only need to pass token, maxPerCall, maxPerWindow, and windowSeconds.Python
aset_spending_policy, aget_spending_policy, aremove_spending_policy.
Validation Rules
The SDK validates before submitting to the contract:On-Chain Enforcement
The contract enforces spending limits during__execute__() for session-signed transactions:
- Tracked selectors:
transfer,approve,increase_allowance,increaseAllowance - Per-call check: If
amount > maxPerCall, transaction reverts with “Spending: exceeds per-call” - Window check: If
spentInWindow + amount > maxPerWindow, transaction reverts with “Spending: exceeds window limit” - Auto-reset: When
now >= windowStart + windowSeconds, the window resets to zero
