Installation
npm install @quickscope/sdk
Usage
Initialization
First, initialize the Quickscope
class with your location ("frankfurt"
or "nyc"
) and your API key:
import Quickscope from '@quickscope/sdk';
// OR
const Quickscope = require('@quickscope/sdk');
const quickscope = new Quickscope("frankfurt", "your-api-key");
Method: getSwapBest
getSwapBest
Description
The getSwapBest
method generates a ready-to-sign, base64-encoded Solana transaction that performs a token swap using the best available quote from all supported liquidity providers. It handles route selection, slippage calculation, and transaction building in a single step.
Use this method when you want the fastest path from quote to transaction without specifying providers or pools manually.
Parameters
{
payer: string,
from: string,
to: string,
amount: number,
slippage: number,
priorityFee: number,
useJito: boolean,
fee?: {
feePercentage?: number,
feeLamports?: number,
feeRecipient?: { address: string; percentageBPS: number; }[],
},
}
- payer: (string) – The wallet address (base58) that will pay for and sign the transaction.
- from: (string) – The mint address of the token being swapped from.
- to: (string) – The mint address of the token being swapped to.
- amount: (number) – The input amount in base units (e.g., lamports).
- slippage: (number) – Acceptable slippage in basis points (e.g., 50 = 0.5%).
- priorityFee: (number) – Optional micro-lamport priority fee. Can be set to 0 to disable.
- useJito: (boolean) – If
true
, includes the transaction in a Jito bundle for better execution guarantees.
Returns
Promise<swapResponse>
: A promise that resolves to a swapResponse
object containing the transaction or an error.
swapResponse
Type
swapResponse
Typeexport type swapResponse = {
swap?: {
base64Transaction: string;
},
quote?: quoteResult,
error?: string;
error_code?: string;
}
Example
async function fetchBestSwapTx() {
try {
const swap = await quickscope.v1.swap.getSwapBest({
payer: 'E3BmYnxm9LYo2ca9mY7zBr5Say5YUjo17QdoRxPk9yTG', // your wallet address
from: 'So11111111111111111111111111111111111111112', // SOL
to: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
amount: 1000000,
slippage: 100, // 1%
priorityFee: 50000, // 0.00005 SOL
useJito: true
});
console.log('Swap transaction:', swap.swap?.base64Transaction);
// Example output:
// {
// "success": true,
// "result": {
// "swap": {
// "base64Transaction": "AgAAAAAAAA..."
// },
// "quote": {
// "amountIn": 100000000,
// "amountOut": 16373808,
// "minAmountOut": 16046332,
// "prettyAmountOut": 16.373808,
// "slippage": 200,
// "fromMint": {},
// "toMint": {},
// "routePath": [
// "So11111111111111111111111111111111111111112",
// "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
// ],
// "routes": [
// {
// "uuid": "2f69fae1-78f1-4893-9ce7-20cabfec882d",
// "poolId": "FpCMFDFGYotvufJ7HrFHsWEiiQCGbkLCtwHiDnh7o28Q",
// "poolType": "whirlpool",
// "provider": "orca",
// "program": "orca_whirlpool",
// "fromMint": "So11111111111111111111111111111111111111112",
// "toMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
// "amountIn": 100000000,
// "amountOut": 16373808,
// "minAmountOut": 16046332,
// "priceImpact": 0.0083626192
// }
// ]
// }
// }
// }
} catch (error) {
console.error('Error generating swap transaction:', error);
}
}
fetchBestSwapTx();
Error Handling
This method throws or returns an error if:
- No valid quote can be found for the token pair
- One or more input fields are missing or malformed
- The backend fails to build a transaction
You should wrap this call in a try/catch
block and optionally check for the presence of swap in the response: