Spending Limits
Overview
Spending limits are security policies that allow users to control how much your application can spend on their behalf. When users connect to your app via Phantom Connect, they can set maximum spending amounts that are enforced onchain.
How Spending Limits Work
Policy Enforcement
When a transaction is submitted through an embedded wallet:
- Transaction Simulation: Phantom simulates the transaction to calculate its impact on the user’s wallet
- Policy Check: The simulated transaction is checked against the user’s configured spending limit policies
- Approval or Rejection:
- If the transaction is within the spending limit, it proceeds
- If the spending limit is exceeded, the transaction is rejected with a custom error
User Control
Users have full control over their spending limits:
- Setting Limits: During the Phantom Connect flow, users can configure spending limit policies for your application
- Updating Limits: Users can adjust their spending limits at any time through their Phantom wallet settings
- Per-App Policies: Spending limits are configured on a per-application basis, allowing users to set different limits for different apps
Phantom Connect Spending Limits
When users connect to your app via Phantom Connect, they’ll see a permissions screen where they can review and configure the spending limit for your application:
If users want to adjust their spending limit, they can click on the spending limit amount to access the spending limits configuration screen:
Extension Spending Limits
Users can also view and manage spending limits through their Phantom browser extension:
Transaction Constraints
No Bundled or Parallel Transaction Execution when using spending limits
Bundled Transactions Not Supported: Phantom embedded wallets do not support Solana’s parallel transaction execution features, such as Jito bundles or other mechanisms that submit multiple transactions together atomically. Each transaction must be submitted individually and signed before the next can be sent.
What This Means
You cannot use Solana features that execute multiple transactions together, such as:
- Jito Bundles: Cannot bundle multiple transactions (e.g., “send A 1 SOL” + “send B 1 SOL”) to execute atomically together
- Parallel Transaction Execution: Cannot submit transactions that are designed to execute simultaneously on Solana
- Atomic Multi-Transaction Operations: Cannot group multiple transactions into a single atomic operation
Why This Limitation Exists
To accurately enforce spending limits, Phantom must simulate each transaction individually to determine its financial impact. Bundled or parallel transaction execution would:
- Prevent accurate calculation of cumulative spending across multiple transactions
- Create race conditions that could cause your transaction to revert on chain
- Make the final wallet state unpredictable for policy enforcement
Each transaction must be simulated independently, confirmed, and have its spending impact recorded before the next transaction can be signed.
Handling Spending Limit Errors
When a transaction exceeds the user’s spending limit, the transaction will be rejected by the SDK and the user will be requested to adjust their limits.
For the browser SDK, due to it’s lack of UI, your application will receive an error. You should:
- Catch the Error: Handle spending limit errors gracefully in your application
- Inform the User: Display a clear message explaining that the transaction exceeds their spending limit
- Provide Guidance: Direct users to their Phantom wallet settings where they can adjust their spending limits
try {
const result = await solana.signAndSendTransaction(transaction);
console.log('Transaction successful:', result.hash);
} catch (error) {
if (error.code === 'SPENDING_LIMIT_EXCEEDED') {
// Show user-friendly message
showMessage(
'This transaction exceeds your spending limit. ' +
'Please update your spending limit in Phantom settings to continue.'
);
} else {
// Handle other errors
console.error('Transaction failed:', error);
}
}