# Priority Fees

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.

```python
import os
import asyncio

from dotenv import load_dotenv

from solders.keypair import Keypair

from solana.rpc.async_api import AsyncClient

from anchorpy import Wallet

from driftpy.drift_client import DriftClient
from driftpy.keypair import load_keypair
from driftpy.types import TxParams

async def main():
    load_dotenv()
    secret = os.getenv("PRIVATE_KEY") # as a [u64]
    url = os.getenv("RPC_URL") # as a string
    
    keypair = load_keypair(secret)
    wallet = Wallet(kp)
    
    connection = AsyncClient(url)
    
    compute_units_limit = 700_000
    microlamports_per_cu_requested = 100_000
    
    drift_client = DriftClient(
        connection,
        wallet,
        "mainnet", # or "devnet"
        tx_params=TxParams(compute_units_limit, microlamports_per_cu_requested)
    )
    
    await drift_client.add_user(0)
    
    await drift_client.subscribe()
```

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.

```python
@dataclass
class TxParams:
    compute_units: Optional[int]
    compute_units_price: Optional[int]
```

`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:

```python
    drift_client = DriftClient(
        connection,
        wallet,
        "mainnet",
        tx_params=TxParams(1_000_000, 100_000)
    )
```

How much will your transaction cost?\
\
Let's do the math:

$$
\begin{align\*} \text{Compute Units} & = 1,000,000 \ \text{Rate per Compute Unit} & = 100,000 , \text{microlamports} \ \text{Total Cost in Microlamports} & = \text{Compute Units} \times \text{Rate per Compute Unit} \ & = 1,000,000 \times 100,000 \ & = 100,000,000,000 , \text{microlamports} \end{align\*}
$$

$$
\text{Total Cost} = \frac{\text{Total Cost in Microlamports}}{1,000,000 \times 1,000,000,000} = \frac{100,000,000,000}{1,000,000,000,000,000} = 0.0001 , \text{SOL}
$$

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://drift-2.gitbook.io/driftpy-for-dummies/priority-fees.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
