Skip to main content
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 /build endpoint 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.
Jupiter retired the old quote-api.jup.ag/v6 endpoints on October 1, 2025, and recommends Swap API v2 over v1 (/quote and /swap). This guide uses the v2 Router endpoint, https://api.jup.ag/swap/v2/build, which returns raw swap instructions for a transaction you send through your own node. api.jup.ag works without a key at a low request rate and takes an x-api-key header for higher tiers (get a key at portal.jup.ag); lite-api.jup.ag is being phased out.

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.
So in theory — the higher the priority fee, the more chances you have to skip ahead and become a part of the state of the chain than the others you are racing against. Let’s implement adding a proper priority fee to our transaction based on an interaction with the Jupiter aggregator.

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.
Get yourself a Chainstack Solana node.

Overview

Here’s how it’s going to work:
  1. Get the priority fee data for the recent 150 blocks with the getRecentPrioritizationFees call from a Chainstack Solana node, and calculate the compute unit price.
  2. Get the swap instructions for the token pair (route, liquidity pools, and the accounts they use) from the Jupiter /build endpoint.
  3. Assemble the transaction with your compute unit price, and simulate it through the Chainstack Solana node to set the compute unit limit.
  4. 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 with solders. Install the dependencies:
The complete script:
jupiter_swap.py
A few notes on the current Jupiter API:
  • Compute unit price. /build returns a SetComputeUnitPrice instruction with Jupiter’s own estimate in computeBudgetInstructions. 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 the computeUnitPricePercentile parameter (medium, high, veryHigh, or a value in basis points).
  • Compute unit limit. /build doesn’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. /build returns instructions for a v0 transaction, plus the addresses in each lookup table in addressesByLookupTableAddress, so solders compiles the message without fetching the tables. With transactionVersion=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.

Conclusion

Solana is a very fun and extremely lively ecosystem, so have fun building, keep and eye on the all changes and how the fee market develops — this can give you an edge. And use Chainstack, of course.

Ake

Ake Director of Developer Experience @ Chainstack
Talk to me all things Web3
20 years in technology | 8+ years in Web3 full time years experience
Last modified on November 12, 2026