Requires CHIPI v33 wallets. See the Spending Policies guide for concepts and use cases.
sessions.setSpendingPolicy()
Set a spending policy for a session key + token pair. Requires owner signature.Usage
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
encryptKey | string | Yes | PIN to decrypt owner’s private key |
wallet | WalletData | Yes | Wallet data with encrypted private key |
spendingPolicyConfig.sessionPublicKey | string | Yes | Session key to apply the policy to |
spendingPolicyConfig.token | string | Yes | ERC-20 token contract address |
spendingPolicyConfig.maxPerCall | bigint | Yes | Max amount per single call (u256) |
spendingPolicyConfig.maxPerWindow | bigint | Yes | Max cumulative amount in rolling window (u256) |
spendingPolicyConfig.windowSeconds | number | Yes | Rolling window duration in seconds (u64) |
Return Value
Promise<string> — Transaction hash of the on-chain set_spending_policy call.
sessions.getSpendingPolicy()
Query a spending policy from the contract. Read-only, no signature or gas required.Usage
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
walletAddress | string | Yes | Wallet contract address |
sessionPublicKey | string | Yes | Session public key |
token | string | Yes | ERC-20 token contract address |
Return Value
SpendingPolicyData:
| Field | Type | Description |
|---|---|---|
maxPerCall | bigint | Maximum amount per single call |
maxPerWindow | bigint | Maximum cumulative amount in rolling window |
windowSeconds | number | Rolling window duration in seconds |
spentInWindow | bigint | Amount spent in the current active window |
windowStart | number | Unix timestamp when the current window started |
sessions.removeSpendingPolicy()
Remove a spending policy. After removal, the session has no limits for this token. Requires owner signature.Usage
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
encryptKey | string | Yes | PIN to decrypt owner’s private key |
wallet | WalletData | Yes | Wallet data with encrypted private key |
sessionPublicKey | string | Yes | Session key to remove policy from |
token | string | Yes | ERC-20 token contract address |
Return Value
Promise<string> — Transaction hash of the on-chain remove_spending_policy call.