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 = {
  quotes: quotesResponseMap[];
  error?: string;
  error_code?: string | number;
}

quotesResponseMap Type

export type quotesResponseMap = {
  uuid: string;
  poolId: string;
  poolType: string;
  provider: string;
  program: string;
  amountIn: number;
  amountOut: number;
  fromMint: string;
  toMint: string;
  priceImpact: number;
}

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:
        // {
        //   uuid: "42f5d124-00c6-408a-b857-ccb6dcb218c2",
        //   poolId: "orca_SOL_USDC_whirlpool",
        //   poolType: "Whirlpool",
        //   provider: "orca",
        //   program: "Whirlpool",
        //   amountIn: 1000000,
        //   amountOut: 998000,
        //   fromMint: "So11111111111111111111111111111111111111112",
        //   toMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
        //   priceImpact: 0.19
        // }
    } 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.