/build response includes computeBudgetInstructions with the compute unit price but not the compute unit limit. You need to simulate to determine the correct limit.
Why: since you are building your own transaction with custom instructions, the CU usage will differ from a base swap. The simulation gives you the actual number, and you set the limit with a safety buffer.
Why this matters
Priority fee cost is calculated as:Customise compute unit price
The/build response bakes a compute unit price into computeBudgetInstructions based on recent network priority fees. Use computeUnitPricePercentile to control how aggressively you bid:
When
mode=fast is set and no computeUnitPricePercentile is provided, the default is the 90th percentile instead of the 50th.
You can also override entirely by replacing the computeBudgetInstructions from the response with your own setComputeUnitPrice instruction.
Cap the compute unit price
Decode the compute unit price from thesetComputeUnitPrice instruction in computeBudgetInstructions and clamp it to your own maximum. The instruction data is base64: a 1-byte discriminator (3 for setComputeUnitPrice) followed by the price as a little-endian u64 in micro-lamports.
/build response before converting the instructions for your SDK, so the same check works with both @solana/kit and @solana/web3.js. With the clamp in place, your worst-case priority fee is bounded: CUP cap × CU limit. A lower cap can slow landing during congestion, so pick a maximum that matches the fees you are willing to pay.
If you already maintain your own priority fee estimate, you can skip the decode: drop the returned computeBudgetInstructions and set your own setComputeUnitPrice with the lower of your estimate and your cap. A low computeUnitPricePercentile is not a substitute for a cap, because a percentile of an inflated fee distribution can still be extreme.
Estimate compute unit limit
- Build the transaction with all your instructions + max CU limit (1,400,000)
- Simulate with
replaceRecentBlockhash: trueto get actual CU consumed - Rebuild with 1.2x the simulated value (capped at 1,400,000) as the CU limit
- Add the CU price instruction from the
/buildresponse
Related
- Build for the full code example with CU simulation
- Transaction Submission to submit via Jupiter’s transaction landing infrastructure with SOL tips for priority processing
- Reduce Transaction Size for other optimisations
