Solana Swap Integration Guide
How to execute same chain swap on Solana chain using Fly Trade's APIs
This guide shows how to execute a swap on Solana using the Fly Trade's API in 2 steps:
Get a quote (pricing + route + constraints)
Fetch transaction payload, then build, sign, and send the Solana transaction
Prerequisites
A Solana RPC connection
A wallet that can sign Solana transactions (Phantom / Backpack / Solflare / or a backend Keypair)
Token mint addresses for the assets you want to swap
How the Flow Works
Magpie supports two ways to execute a swap on Solana. Regardless of the method, the high-level flow is:
Call
/aggregator/quoteto receive aquoteIdand estimated output.Call
/aggregator/transactionwith thequoteIdto receive the transaction payload.Depending on your integration, either:
Deserialize the provided serialized transaction (recommended), or
Construct the transaction manually from
rawData,accounts, LUTs, and compute budget fields.
Sign the transaction with the user wallet (or fee payer).
Send it to the Solana network.
Step 1 — Get a Quote
Endpoint
Method:
GETPath:
/aggregator/quote
Required parameters
network
solana
fromTokenAddress
Token mint to swap from. For native SOL use 11111111111111111111111111111111
toTokenAddress
Token mint to swap to. For native SOL use 11111111111111111111111111111111
sellAmount
Amount in the smallest unit (e.g., lamports for SOL, for 1 SOL write 1000000000)
slippage
Allowed slippage (e.g., 0.005 for 0.5%)
fromAddress
Wallet address initiating the swap
toAddress
Wallet address receiving the swapped tokens
gasless
Please use false on Solana. Setting true will be overridden to falsefor now, gasless support for Solana will be added in a future release
Optional Notes
Affiliate Fee
Affiliate fees are not supported on Solana. This feature is available only on EVM chains. If you need affiliate fee logic on Solana, you must implement it on your side (e.g., adjusting balances before/after the swap).
feePayer (PDA Flow)
You can use a PDA (Program Derived Address) as the fromAddress as long as a normal wallet address is supplied as the feePayer.
The
feePayermust be a real wallet, not a PDA.The
feePayermust be whitelisted by Fly Trade before use. Contact us with the address to whitelist it.
This allows advanced workflows where a PDA owns the source tokens, but another wallet pays the transaction fees.
Using a Non-ATA Token Account
If the source token is stored in a non-ATA (Associated Token Account), you must explicitly specify which token account should be used for the swap.
To do this, set the fromAddress parameter to:
This tells us which SPL token account to read from.
Example
Where:
7VHUFJHWu2CuExkJcJrzhQPJ2oygupTWkL2A2For4BmE→ the owner wallet3emsAVdmGKERbHjmGfQ6oZ1e35dkf5iYcS6U4CPKFVaa→ the specific SPL token account (non-ATA)
If your user has multiple token accounts for the same mint, this ensures the correct one is used during the swap.
Example request
Example response
Save the id as quoteId for Step 2.
Step 2 — Get Transaction Payload
Endpoint
Method:
GETPath:
/aggregator/transaction
Required parameters
quoteId
The quote id returned from Step 1
Example request
The response contains:
rawData(base64 instruction data)accounts(account metas)addressLookupTables(LUTs)gasLimit/gasPrice(compute budget hints)
Example response
Step 3 — Execute the Swap Transaction
GET /aggregator/transaction returns everything you need to execute the swap on Solana. There are two valid ways to construct the transaction:
Method A (Recommended): deserialize the returned
datadirectly into aVersionedTransactionMethod B (Manual construction): build the v0 message yourself from
rawData,accounts, LUTs, and compute budget settings
Method A (Recommended): Deserialize data → sign → send
data → sign → sendThe /aggregator/transaction response includes:
data: a base64-encoded, fully-formed Solana VersionedTransactionfrom: user / fee payer (informational)addressLookupTables: optional metadata (not required for this method)
Example (TypeScript)
Usage example
Method B (Manual): Build v0 transaction from rawData + accounts + LUTs
rawData + accounts + LUTsUse this method if you need to:
add custom instructions
override compute budget settings
or construct the tx explicitly for advanced flows
This is the “manual build” approach: fetch LUT accounts, add compute budget ixs, create the router instruction from rawData, then compile to v0.
Example (TypeScript)
Sign + send
End-to-End (Recommended): Quote → Transaction → Deserialize → Sign → Send
Last updated