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 call the
/buildendpoint of Jupiter’s Swap API v2 for the raw swap instructions. - We calculate our priority fee by fetching recent block data via
getRecentPrioritizationFees, then take the median of the non-zero slots and multiply it by a user-defined factor. - We assemble the transaction ourselves with that compute unit price and a compute unit limit measured by simulation. The priority fee, paid on top of the 5000-lamport base fee, helps the transaction land under congestion.
- The flow makes one Jupiter call and uses your own Solana node (e.g., Chainstack) for fee data, simulation, and the final 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 the priority fee data for the recent 150 blocks with the
getRecentPrioritizationFeescall from a Chainstack Solana node, and calculate the compute unit price. -
Get the swap instructions for the token pair (route, liquidity pools, and the accounts they use) from the Jupiter
/buildendpoint. - Assemble the transaction with your compute unit price, and simulate it through the Chainstack Solana node to set the compute unit limit.
- Sign the transaction and send it through the Chainstack Solana node.
Implementation
The flow is: estimate a priority fee from recent on-chain data, get the swap instructions from Jupiter, assemble the transaction with that fee, then simulate, 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 build and sign the transaction withsolders.
Install the dependencies:
jupiter_swap.py
- Compute unit price.
/buildreturns aSetComputeUnitPriceinstruction with Jupiter’s own estimate incomputeBudgetInstructions. The script leaves it out and sets the price from step 1. To use Jupiter’s estimate instead, include those instructions and choose the level with thecomputeUnitPricePercentileparameter (medium,high,veryHigh, or a value in basis points). - Compute unit limit.
/builddoesn’t set one. The script simulates at the 1,400,000 maximum, then sets the limit to 1.2 times the units consumed. The priority fee in lamports is the compute unit price times the compute unit limit divided by 1,000,000, rounded up, so a tighter limit costs less. - Versioned transactions.
/buildreturns instructions for a v0 transaction, plus the addresses in each lookup table inaddressesByLookupTableAddress, sosolderscompiles the message without fetching the tables. WithtransactionVersion=1, it returns no compute budget instructions; a v1 transaction carries its compute unit limit and priority fee in the message instead. - 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 of the non-zero slots (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.
