getSwapCustom

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

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;
}
  • 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

export type swapResponse = {
  swap?: {
    base64Transaction: string;
  };
  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:
        // {
        //   swap: {
        //     base64Transaction: "AAABAgMEBQYH..."
        //   }
        // }
    } 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: