Skip to main content
Spending policies enforce per-token limits on ERC-20 operations executed by session keys. The CHIPI wallet contract enforces these automatically during transaction execution.
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

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

ParameterTypeRequiredDescription
encryptKeystringYesPIN to decrypt owner’s private key
walletWalletDataYesWallet data with encrypted private key
spendingPolicyConfig.sessionPublicKeystringYesSession key to apply the policy to
spendingPolicyConfig.tokenstringYesERC-20 token contract address
spendingPolicyConfig.maxPerCallbigintYesMax amount per single call (u256)
spendingPolicyConfig.maxPerWindowbigintYesMax cumulative amount in rolling window (u256)
spendingPolicyConfig.windowSecondsnumberYesRolling 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

ParameterTypeRequiredDescription
walletAddressstringYesWallet contract address
sessionPublicKeystringYesSession public key
tokenstringYesERC-20 token contract address

Return Value

SpendingPolicyData:
FieldTypeDescription
maxPerCallbigintMaximum amount per single call
maxPerWindowbigintMaximum cumulative amount in rolling window
windowSecondsnumberRolling window duration in seconds
spentInWindowbigintAmount spent in the current active window
windowStartnumberUnix 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

ParameterTypeRequiredDescription
encryptKeystringYesPIN to decrypt owner’s private key
walletWalletDataYesWallet data with encrypted private key
sessionPublicKeystringYesSession key to remove policy from
tokenstringYesERC-20 token contract address

Return Value

Promise<string> — Transaction hash of the on-chain remove_spending_policy call.