The ComputeBudgetProgram is the native Solana program that lets developers control transaction fees and resource limits. It provides two primary instructions: setComputeUnitPrice and setComputeUnitLimit. Including these instructions in your transaction gives you full control over scheduling priority and CU budget.
ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 100000 }) sets the fee you are willing to pay per compute unit. This instruction must be added before your main transaction instructions. The default CU price is 0, meaning no priority fee, which means your transaction competes purely on a first-come, first-served basis.
Including both setComputeUnitPrice and setComputeUnitLimit is considered best practice — it maximizes scheduling priority while preventing you from paying for CUs your transaction never uses.
Solana Foundation Developer Docs
ComputeBudgetProgram.setComputeUnitLimit({ units: 50000 }) caps the maximum CUs your transaction can consume. If omitted, the default limit is calculated from the number and type of instructions (200,000 CUs per non-builtin instruction). Setting this too low will cause your transaction to fail with a "compute budget exceeded" error, so always simulate first using simulateTransaction and add a small buffer (e.g., 10–20%) to the estimated CU usage.
Both instructions together allow you to build highly optimized transaction pipelines for DeFi protocols, NFT minting, trading bots, and any latency-sensitive Solana application. Import ComputeBudgetProgram from @solana/web3.js to get started.
