Skip to main content
The /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:
priority fee = compute unit price × compute unit limit
A tighter CU limit directly reduces the priority fee you pay. Setting it to the maximum (1,400,000) when you only use 200,000 means you pay 7x more than necessary. See Solana fee structure for details.

Pattern

  1. Build the transaction with all your instructions + max CU limit (1,400,000)
  2. Simulate with replaceRecentBlockhash: true to get actual CU consumed
  3. Rebuild with 1.2x the simulated value (capped at 1,400,000) as the CU limit
  4. Add the CU price instruction from the /build response
The Build Custom Transactions code example demonstrates this in steps 4-5 (kit) with full working code.
Setting the CU limit too tight causes transaction failures. Always use at least a 1.2x buffer over the simulated value.