⛏️getQuote

Description

The getQuote function returns an object containing the contract address and quotes for a given token swap between two chains, based on the source and destination chain, source and destination tokens, and the amount to be swapped.

If the request is unsuccessful, it returns an error message.

Parameters

ParameterTypeDescription

srcChain

string

The name of the source blockchain network (e.g., ETH, AVA, BSC, Polygon, Klaytn), and all specified networks are on the mainnet.

destChain

string

The name of the destination blockchain network (e.g., ETH, AVA, BSC, Polygon, Klaytn), and all specified networks are on the mainnet.

fromToken

string

The contract address of the token being swapped on the source chain

toToken

string

The contract address of the token being swapped on the destination chain

amount

string

The amount of tokens being swapped

Response

PropertyTypeDescription

contractAddress

string

The contract address of the token on the destination chain

quote

string

The estimated amount of tokens to receive on the destination chain after the swap

code

string

Error code if the quote is unsuccessful

msg

string

Error message if the quote is unsuccessful

Example Request and Response

Prerequisites

Before making requests with Nest SDK, you must have it installed.

You can install Nest SDK using either npm or yarn. Use the following commands to install Nest SDK:

npm install @nest25/xy-finance-lib
OR
yarn add @nest25/xy-finance-lib

Request

Here is an example of how to make a getQuote request using the Nest SDK:

// import Nest SDK library
const { xySwap } = require('@nest25/xy-finance-lib');

// create xySwap instance
const swap = new xySwap();

async function main() {
  // get quote
  const response = await swap.getQuote(
    'klaytn',
    'klaytn',
    '0xCF87f94fD8F6B6f0b479771F10dF672f99eADa63',
    '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
    '10',
  );
  console.log(response);
}
// run main function
main();

```

Response

{
      contractAddress: '0x52075Fd1fF67f03beABCb5AcdA9679b02d98cA37',
      quote: {
        sourceChainSwaps: { dexNames: [Array], fromToken: [Object], toToken: [Object] },
        crossChainSwap: null,
        destChainSwaps: null,
        toTokenAmount: '0.8281407505663061'
      }
    }

Use Cases

  • Token swapping: The getQuote function can be used by decentralized exchanges to get a quote for a cross-chain token swap before initiating a trade, ensuring the accuracy of the transaction.

  • Portfolio management: The function can be used to help portfolio managers determine the expected outcome of a token swap before making the trade.

  • Arbitrage opportunities: The function can be used to identify potential arbitrage opportunities by comparing the estimated swap amount with the current market price of the tokens on both chains.

Last updated