Part of the How to land transactions on Solana guide.TLDR:
- Jupiter offers a quick way to swap tokens on Solana but lacks a Python SDK, so we query Jupiter’s public API for quotes and transaction data.
- We calculate our priority fee by fetching recent block data via
getRecentPrioritizationFees, then derive the median fee and multiply it by a user-defined factor. - Adding this priority fee to the raw Jupiter transaction data (plus the base fee of 5000 lamports) helps ensure faster block inclusion under congestion.
- The entire flow uses both Jupiter endpoints (quote + swap) and a private Solana RPC (e.g., Chainstack) for the final transaction broadcast, giving you more control over performance and reliability.
Main article
With its cumulative volume in USD billions, Jupiter is one of the top DEX aggregators on Solana. In this tutorial, we are going to have a look at how add our own prioritization fees to swap for a token pair through a Jupiter aggregator route. As Jupiter does not have a Python SDK at the time of this tutorial, it’s more fun doing this in Python. For JavaScript, check out the Jupiter developer docs.Transaction fees on Solana
The topic of transactions fees on Solana is both a nascent development and its own can of worms at the same time, so we are not going to do a deep dive into this. Here’s however what you need to know in a succinct form for this tutorial:- Base fee — fixed 5000 lamports (0.000005 SOL) per transaction signature, which 99% of the time means 5000 lamports per transaction
- Priority fee — a non-fixed amount that you can include in your transaction on top of the 5000 lamports base fee to get ahead of others in the queue for the block inclusion of the current leader.
Run Solana mainnet and devnet nodes on Chainstack
Start for free and get your app to production levels immediately. No credit card required. You can sign up with your GitHub, X, Google, or Microsoft account.Overview
Here’s how it’s going to work:- Get a token pair price quote from the Jupiter API.
-
Get the priority fees data from the recent 150 blocks with the
getRecentPrioritizationFeescall from a Chainstack Solana node. - Calculate the priority fee to include with your transaction.
-
Submit the transaction through the Chainstack Solana node:
- Transaction data (token pair exchange rate, liquidity pool) from the Jupiter API quote
- Priority fee based on the raw chain data obtained through the Chainstack Solana node
Implementation
The flow is: estimate a priority fee from recent on-chain data, get a quote from Jupiter, build the swap transaction with that fee, then sign and send it through your own Solana node. Jupiter doesn’t have an official Python SDK, so we call its REST API directly and sign withsolders.
Install the dependencies:
jupiter_swap.py
- Priority fee shape.
prioritizationFeeLamports.priorityLevelWithMaxLamportslets Jupiter pick a fee at the chosenpriorityLevel(medium,high, orveryHigh) capped atmaxLamports. Here we cap it at the median-derived value so we never overpay during a fee spike. dynamicComputeUnitLimit: truemakes Jupiter simulate the swap and set an accurate compute-unit limit, which both improves landing and avoids overpaying (the priority fee iscompute_unit_price × compute_unit_limit).- Versioned transactions. Jupiter returns a base64
VersionedTransaction; sign it withsoldersand broadcast the raw bytes through your node. - Why the median. Fees over the recent window can include random astronomical outliers — basing your fee on the max can drain your wallet. The median (optionally bumped by
PRIORITY_MULTIPLIER) is a safer baseline. Tune it for your needs.
The companion repository jupiter-swaps-priority-fees-python has the full project. The base fee on Solana is a fixed 5000 lamports per signature; the priority fee above is added on top.
