Dras accumsan nulla nec lacus ultricies placerat.
  • By admin
  • July 29, 2024
  • No Comments

How to Set Solana Priority Fees

Adding priority fees to your Solana transactions programmatically is straightforward using the ComputeBudgetProgram from the @solana/web3.js library. There are two key instructions you can include in your transaction to control fees and compute budget.

Step 1: Set Compute Unit Limit — Use ComputeBudgetProgram.setComputeUnitLimit() to specify the maximum compute units your transaction may consume. Setting this accurately can reduce your total fee cost significantly.

Solana web3.js priority fee setup
ComputeBudgetProgram example

Step 2: Set Compute Unit Price — Use ComputeBudgetProgram.setComputeUnitPrice() to specify your bid in microlamports per compute unit. This is the value that directly controls your transaction priority in the validator queue.

Both instructions must be added at the beginning of your transaction instruction array before sending to the network.

For production applications, avoid hardcoding your compute unit price. Fetch recent fee data using connection.getRecentPrioritizationFees() or a priority fee API, then dynamically calculate an appropriate fee based on current network conditions.

Solana priority fee implementation guide

Wallet providers like Phantom automatically apply priority fees to their generated transactions. For DApp developers who construct transactions manually, setting fees programmatically gives precise control over cost and transaction landing rates.

Leave a Reply

Your email address will not be published. Required fields are marked *