Priority Fees
How to set Priority Fees in the Drift Client.
Here is the setup code we discussed on the last page for initializing a Drift Client, with one notable addition: the introduction of TxParams
in the constructor.
The TxParams
object represents the priority fees you want to add on to any transaction sent with the Drift Client. It is set by default to request 600,000 compute units with zero priority fee.
Here's what the TxParams
object looks like and what each field means.
compute_units
- the number of compute units you intend to request for all transactions sent from the Drift Client. This value will typically range from 300,000 to a maximum of 1,400,000. Any values larger than 1.4m here will be overridden by the Solana runtime and set to 1.4m. If compute_units_price
is also set with this value, you will pay more SOL in transaction fees the higher the compute_units
value increases.
compute_units_price
- the number of microlamports you intend to pay as a priority fee per compute unit requested. This value will typically range from 100,000 to 100,000,000. The higher this number is, the more SOL you will pay in transaction fees.
Let's look at an example of how priority fee calculations work. Say you set compute_units
to 1,000,000 and compute_units_price
to 100,000 like this:
How much will your transaction cost? Let's do the math:
Plus the 5000 lamports from the default fee yields a total cost of .000105 SOL for that transaction. it's important to note that raising your priority fee does not guarantee inclusion in the block! The only data that we have regarding this topic is that transactions with any priority fee land more consistently than transactions without priority fees. Therefore, if you already have a priority fee set and are seeing dropped transactions, increasing your priority fee may help, but there is no guarantee that it will result in better transaction confirmation rates. However, if you do not have priority fees set at all, setting a priority fee of even 10,000 microlamports may significantly increase your chances of landing a transaction.
Last updated