How to Set Solana Priority Fee — Step-by-Step Guide
Adding a priority fee to your Solana transaction is straightforward using the Compute Budget Program. By including specific instructions before your main transaction logic, you can bid for higher scheduling priority in the validator queue.
Step 1 — Install Dependencies
Ensure you have the latest version of @solana/web3.js installed in your project. The ComputeBudgetProgram utility class is included in the library and provides all the methods needed for priority fee configuration.
Step 2 — Create a Compute Unit Price Instruction
Use ComputeBudgetProgram.setComputeUnitPrice({ microLamports: VALUE }) to create an instruction that sets your desired fee per compute unit. For dynamic fee setting in production, replace the static value with a real-time estimate from getRecentPrioritizationFees.
Step 3 — Set the Compute Unit Limit
Always pair your price instruction with ComputeBudgetProgram.setComputeUnitLimit({ units: VALUE }). This caps the maximum compute your transaction may consume. Without this, the scheduler uses the default CU budget (which is often unnecessarily large, increasing your fee unnecessarily). Simulate your transaction first to find the actual CU consumption, then add a 15% buffer.
Step 4 — Add Instructions to Your Transaction
Add both Compute Budget instructions as the first instructions in your transaction, before any program invocations. The order matters — they must precede the main logic.
Step 5 — Dynamic Fee Estimation (Recommended)
For production applications, hardcoding a static microLamports value is not ideal. Instead, call getRecentPrioritizationFees before each transaction to get the current fee floor, then select a percentile above the median based on your urgency. The Helius Priority Fee API simplifies this to a single API call that returns six priority levels (Minimum, Low, Medium, High, VeryHigh, UnsafeMax) as ready-to-use values.
Best Practices Summary
- Always set both
setComputeUnitPriceANDsetComputeUnitLimittogether - Add Compute Budget instructions first in your transaction
- Simulate before executing to measure actual CU usage
- Use dynamic fee estimation in production — never hardcode in high-stakes contexts
- Monitor transaction success rates and adjust fee strategy accordingly
- For MEV or arbitrage bots, use the Very High or UnsafeMax tier during competitive periods



