Swap API Documentation
API now supports:
Endpoints
GET /swap
curl --location 'https://swap-v2.solanatracker.io/swap?from=So11111111111111111111111111111111111111112&to=4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R&fromAmount=1&slippage=10&payer=PAYER_ADDRESS'
POST /swap
curl --location 'https://swap-v2.solanatracker.io/swap' \
--header 'Content-Type: application/json' \
--data '{
"from": "So11111111111111111111111111111111111111112",
"to": "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R",
"amount": 1,
"slippage": 15,
"payer": "arsc4jbDnzaqcCLByyGo7fg7S2SmcFsWUzQuDtLZh2y",
"priorityFee": 0.0005,
"feeType": "add",
"fee": "arsc4jbDnzaqcCLByyGo7fg7S2SmcFsWUzQuDtLZh2y:0.1"
}'
Request Parameters
Both GET and POST requests support the following parameters:
Parameter | Description | Example |
---|---|---|
from | The base token address | So11111111111111111111111111111111111111112 (SOL) |
to | The quote token address | 4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R (RAY) |
amount | The amount of the base token to swap. Can be a specific value, “auto” to use full wallet amount, or a percentage (e.g., “50%”) to use that portion of the wallet balance | 1 , "auto" , or "50%" |
slippage | Maximum acceptable slippage percentage | 10 |
payer | Public key of the wallet sending the transaction | PAYER_ADDRESS |
Optional Parameters
Parameter | Description | Example |
---|---|---|
priorityFee | Amount in SOL to increase transaction processing priority | 0.000005 |
txVersion | Transaction version ("v0" or "legacy" ) | "v0" |
fee | Charge a custom fee to your users for each transaction (earn sol for each swap) | WALLET_ADDRESS:PERCENTAGE |
feeType | Fee application type (default: "add" ) | "add" or "deduct" |
Note: The feeType
parameter is set to "add"
by default. The "deduct"
option is only used when the from
address is SOL.
Example Response
{
"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":"So11111111111111111111111111111111111111112",
"decimals":9
},
"quoteCurrency":{
"mint":"4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R",
"decimals":6
},
"platformFee":9000000,
"platformFeeUI":0.009
},
"timeTaken":0.016,
"type":"legacy"
}
Loading the Transaction
const serializedTransactionBuffer = Buffer.from(res.txn, "base64");
let txn;
if (res.type === 'v0') {
txn = VersionedTransaction.deserialize(serializedTransactionBuffer);
} else {
txn = Transaction.from(serializedTransactionBuffer);
}
if (!txn) return false;
Sending the Transaction
Using React Wallet Adapter
if (res.type === 'v0' && txn) {
await wallet.signTransaction(txn);
}
const txid = await wallet.sendTransaction(txn, connection, {
skipPreflight: true,
maxRetries: 4,
});
Using NodeJS
const keypair = Keypair.fromSecretKey(bs58.decode('YOUR_SECRET_KEY'));
let txid;
if (res.type === 'v0' ) {
const txn = VersionedTransaction.deserialize(serializedTransactionBuffer);
txn.sign([keypair]);
txid = await connection.sendRawTransaction(txn.serialize(), {
skipPreflight: true,
});
} else {
const txn = Transaction.from(serializedTransactionBuffer);
txn.sign(keypair);
const rawTransaction = txn.serialize();
txid = await connection.sendRawTransaction(rawTransaction, {
skipPreflight: true,
});
}
Fees
We charge a 0.5% fee on each successful transaction. For high-volume usage on public bots or sites, contact us via Discord or email ([email protected]) to discuss reduced fees.