Documentation Index
Fetch the complete documentation index at: https://docs.chipipay.com/llms.txt
Use this file to discover all available pages before exploring further.
Spending policies enforce per-token limits on ERC-20 operations executed by session keys. The CHIPI wallet contract enforces these automatically during transaction execution.
sessions.setSpendingPolicy()
Set a spending policy for a session key + token pair. Requires owner signature.
Usage
const txHash = await sdk.sessions.setSpendingPolicy({
encryptKey: "user-secure-pin",
wallet: userWallet,
spendingPolicyConfig: {
sessionPublicKey: session.publicKey,
token: "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
maxPerCall: 1_000_000n,
maxPerWindow: 50_000_000n,
windowSeconds: 86400,
},
}, bearerToken);
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
const policy = await sdk.sessions.getSpendingPolicy({
walletAddress: "0x04abc...def",
sessionPublicKey: session.publicKey,
token: "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
});
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 |
Returns all zeros if no policy is set (meaning no enforcement).
sessions.removeSpendingPolicy()
Remove a spending policy. After removal, the session has no limits for this token. Requires owner signature.
Usage
const txHash = await sdk.sessions.removeSpendingPolicy({
encryptKey: "user-secure-pin",
wallet: userWallet,
sessionPublicKey: session.publicKey,
token: "0x033068f6539f8e6e6b131e6b2b814e6c34a5224bc66947c47dab9dfee93b35fb",
}, bearerToken);
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.