getQuoteBest

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: getQuoteBest

Description

The getQuoteBest method returns the single best quote available across all liquidity providers for a given token pair, amount, and slippage tolerance. This quote reflects the most optimal output amount, factoring in fees and slippage impact.

Use this method when you want a quick and simplified way to fetch the top route without manually comparing all quotes.


Parameters

{
  from: string;
  to: string;
  amount: number;
  slippage: number;
}
  • 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%).

Returns

Promise<quoteResponseMap>: A promise that resolves to an object containing an array of quote options and optional error fields.

quoteResponseMap Type

export type quoteResponseMap = {
    quote?: null | quoteResult,
    error?: null | string,
    error_code?: null | number | string,
}

quoteResult Type

export type quoteResult = {
    amountIn: number,
    amountOut: number,
    minAmountOut: number,
    prettyAmountOut: number,
    fromMint: SafeMint,
    toMint: SafeMint,
    slippage?: number,
    routes: Route[],
    routePath: string[],
}

SafeMint Type

export type SafeMint = {
    symbol: string;
    name: string;
    uuid: string;
    address: string;
    image: string;
    type: string;
    decimals: number;
}

Route Type

export type Route = {
    uuid: string,
    poolId: string,
    poolType: string,
    provider: string,
    program: string;
    amountIn: number,
    amountOut: number,
    minAmountOut?: number,
    fromMint: string,
    toMint: string,
    priceImpact: number,
    slippage?: number,
    error?: {
        code: string,
        message: string,
    },
}

Example

async function fetchBestQuote() {
    try {
        const result = await quickscope.v1.quote.getQuoteBest({
            from: 'So11111111111111111111111111111111111111112', // SOL
            to: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
            amount: 1000000, // 0.001 SOL
            slippage: 50     // 0.5% slippage
        });

        console.log('Best quote:', result.quotes[0]);

        // Example output:
        // {
        //   "quote": {
        //     "amountIn": 100000000,
        //     "amountOut": 15438989,
        //     "minAmountOut": 15130209,
        //     "prettyAmountOut": 15.438989,
        //     "slippage": 200,
        //     "fromMint": {},
        //     "toMint": {},
        //     "routePath": [
        //       "So11111111111111111111111111111111111111112",
        //       "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
        //     ],
        //     "routes": [
        //       {
        //         "uuid": "4279b7a7-76fc-4462-8de6-2c3059668802",
        //         "poolId": "5yuefgbJJpmFNK2iiYbLSpv1aZXq7F9AUKkZKErTYCvs",
        //         "poolType": "damm",
        //         "provider": "meteora",
        //         "program": "meteora_damm",
        //         "amountIn": 100000000,
        //         "amountOut": 15438989,
        //         "minAmountOut": 15130209,
        //         "fromMint": "So11111111111111111111111111111111111111112",
        //         "toMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        //         "priceImpact": 0.009
        //       }
        //     ]
        //   }
        // }
    } catch (error) {
        console.error('Error fetching best quote:', error);
    }
}

fetchBestQuote();

Error Handling

This method throws an error if:

  • One or both token mints are invalid
  • The amount or slippage is out of range
  • No valid route is found
  • The API encounters an error

Always use a try/catch block for safe integration and better debugging.