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: getSwapCustom
getSwapCustom
Description
The getSwapCustom
method generates a base64-encoded Solana transaction that performs a token swap using a manually specified route. You can customize the path by selecting a specific liquidity provider, AMM program ID, or pool UUID.
Use this method when you want full control over routing logic—ideal for bots, analytics tools, or forced routing scenarios.
Parameters
{
payer: string;
from: string;
to: string;
amount: number;
slippage: number;
priorityFee: number;
useJito: boolean;
provider: string | null;
programId: string | null;
pool: string | null;
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. - provider: (string | null) – (Optional) The name of the provider (e.g.,
"orca"
or"raydium"
). - programId: (string | null) – (Optional) The AMM’s on-chain program ID.
- pool: (string | null) – (Optional) The UUID of a specific liquidity pool.
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 fetchCustomSwapTx() {
try {
const swap = await quickscope.v1.swap.getSwapCustom({
payer: 'E3BmYnxm9LYo2ca9mY7zBr5Say5YUjo17QdoRxPk9yTG',
from: 'So11111111111111111111111111111111111111112',
to: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
amount: 1000000,
slippage: 100,
priorityFee: 50000,
useJito: false,
provider: 'orca',
programId: null,
pool: null
});
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 custom swap transaction:', error);
}
}
fetchCustomSwapTx();
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: