Build Swap Transaction
curl --request GET \
--url https://swap-v2.solanatracker.io/swapimport requests
url = "https://swap-v2.solanatracker.io/swap"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://swap-v2.solanatracker.io/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://swap-v2.solanatracker.io/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://swap-v2.solanatracker.io/swap"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://swap-v2.solanatracker.io/swap")
.asString();require 'uri'
require 'net/http'
url = URI("https://swap-v2.solanatracker.io/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"txn": "BASE64_TX",
"rate": {
"amountIn": 1,
"amountOut": 81.631985,
"minAmountOut": 73.4687865,
"currentPrice": 0.012219167460548153,
"executionPrice": 0.010997250714493338,
"priceImpact": 0.002517,
"fee": 0.000005,
"baseCurrency": {
"mint": "<string>",
"decimals": 123
},
"quoteCurrency": {
"mint": "<string>",
"decimals": 123
},
"platformFee": 9000000,
"platformFeeUI": 0.009
},
"timeTaken": 0.016,
"type": "legacy"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}Legacy Swap API
Build a Solana swap transaction with the Swap API
Build a serialized Solana swap transaction with GET /swap, then sign and broadcast it from your wallet. Covers slippage and priority fee options.
GET
/
swap
Build Swap Transaction
curl --request GET \
--url https://swap-v2.solanatracker.io/swapimport requests
url = "https://swap-v2.solanatracker.io/swap"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://swap-v2.solanatracker.io/swap', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://swap-v2.solanatracker.io/swap",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://swap-v2.solanatracker.io/swap"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://swap-v2.solanatracker.io/swap")
.asString();require 'uri'
require 'net/http'
url = URI("https://swap-v2.solanatracker.io/swap")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"txn": "BASE64_TX",
"rate": {
"amountIn": 1,
"amountOut": 81.631985,
"minAmountOut": 73.4687865,
"currentPrice": 0.012219167460548153,
"executionPrice": 0.010997250714493338,
"priceImpact": 0.002517,
"fee": 0.000005,
"baseCurrency": {
"mint": "<string>",
"decimals": 123
},
"quoteCurrency": {
"mint": "<string>",
"decimals": 123
},
"platformFee": 9000000,
"platformFeeUI": 0.009
},
"timeTaken": 0.016,
"type": "legacy"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}{
"error": "An internal error occurred",
"details": "Unable to fetch pools for token"
}This page covers the older Solana Tracker Swap API at
swap-v2.solanatracker.io. It is still live and charges a platform fee on each swap. Raptor is a separate swap API at raptor.solanatracker.io, currently free with no API key.Overview
The swap endpoint builds token swap transactions on Solana. You receive a serialized transaction that you sign and broadcast using your wallet.This endpoint builds the transaction but does not execute it. You must sign and send the transaction yourself.
Supported Platforms
- Pump.fun - Launch platform tokens
- PumpSwap - Pump.fun liquidity pools
- Orca - Concentrated liquidity
- Meteora - Dynamic pools
- Moonshot - New launches
- Raydium - V4 AMM, CPMM, Launchpad
- Jupiter - Aggregated routing
SDK Examples
import { SolanaTracker } from 'solana-swap';
const tracker = new SolanaTracker('YOUR_API_KEY', 'YOUR_PRIVATE_KEY');
// Basic swap
const swap = await tracker.swap({
from: 'So11111111111111111111111111111111111111112', // SOL
to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
fromAmount: 0.1,
slippage: 10,
payer: 'YOUR_WALLET_ADDRESS',
priorityFee: 0.000005,
txVersion: 'v0'
});
console.log('Transaction:', swap.txn);
In these SDK examples,
slippage: 10 means 10%.from solana_swap import SolanaTracker
tracker = SolanaTracker('YOUR_API_KEY', 'YOUR_PRIVATE_KEY')
# Basic swap
swap = tracker.swap(
from_token='So11111111111111111111111111111111111111112',
to_token='4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
from_amount=0.1,
slippage=10,
payer='YOUR_WALLET_ADDRESS',
priority_fee=0.000005,
tx_version='v0'
)
print('Transaction:', swap['txn'])
curl -X GET "https://swap-v2.solanatracker.io/swap?from=So11111111111111111111111111111111111111112&to=4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R&fromAmount=0.1&slippage=10&payer=YOUR_WALLET_ADDRESS&priorityFee=0.000005&txVersion=v0"
Key Parameters
Amount Formats
ThefromAmount parameter accepts:
- Numeric:
1,0.5- Exact amount - Auto:
"auto"- Entire wallet balance - Percentage:
"50%","25%"- Percentage of balance
Priority Fees
// Manual fee
{ priorityFee: 0.000005 }
// Automatic with level
{
priorityFee: "auto",
priorityFeeLevel: "high" // min, low, medium, high, veryHigh, unsafeMax
}
Partner / Referral Fees
Add your own partner or referral fees for monetization:{
fee: "YOUR_WALLET:0.1", // 0.1% to your wallet
feeType: "add" // or "deduct" (SOL only)
}
Examples
Swap with Auto Amount
// Swap entire balance
const swap = await tracker.swap({
from: 'So11111111111111111111111111111111111111112',
to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
fromAmount: "auto",
slippage: 15,
payer: 'YOUR_WALLET_ADDRESS'
});
Swap with Percentage
// Swap 50% of balance
const swap = await tracker.swap({
from: 'TOKEN_ADDRESS',
to: 'So11111111111111111111111111111111111111112',
fromAmount: "50%",
slippage: 10,
payer: 'YOUR_WALLET_ADDRESS'
});
Swap with Custom Fee
// Add 0.1% fee
const swap = await tracker.swap({
from: 'So11111111111111111111111111111111111111112',
to: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
fromAmount: 1,
slippage: 10,
payer: 'YOUR_WALLET_ADDRESS',
fee: 'YOUR_FEE_WALLET:0.1',
feeType: 'add'
});
Token Accounts and SOL Wrapping
The returned transaction already includes everything needed for the swap to land — you do not need to pre-create token accounts.- Associated Token Accounts (ATAs) are created automatically (idempotent) for the output token and any intermediate hop tokens when the
payerwallet does not already have one. Rent (~0.00203 SOL per account) is paid bypayer. - SOL wrapping/unwrapping is handled automatically: SOL is wrapped to wSOL when used as input, and any leftover wSOL is unwrapped back to native SOL when SOL is the output.
Response Structure
{
"txn": "BASE64_ENCODED_TRANSACTION",
"rate": {
"amountIn": 0.1,
"amountOut": 81.631985,
"minAmountOut": 73.4687865,
"currentPrice": 0.012219167460548153,
"executionPrice": 0.010997250714493338,
"priceImpact": 0.002517,
"fee": 0.000005,
"platformFee": 9000000,
"platformFeeUI": 0.009
},
"timeTaken": 0.016,
"type": "v0"
}
Solana Tracker Platform Fees
Standard fee: 0.5% of transaction value- Deducted from output
- Shown in
platformFee(lamports) andplatformFeeUI(SOL) - Volume discounts available
Contact swap-api@solanatracker.io for volume pricing
Common Errors
| Error | Solution |
|---|---|
| Invalid token address | Verify addresses are valid |
| Invalid amount | Use number, “auto”, or percentage |
| Invalid slippage | Set between 0-100 |
| Token has no pools | Token may be delisted |
| Insufficient liquidity | Try smaller amount |
Next Steps
Rate Endpoint
Get quotes before swapping
JavaScript SDK
Install the SDK
Query Parameters
Was this page helpful?