Aggregator SDK

A thin wrapper over the Panora API to provide functions to swap between any two tokens easily

Installation

Panora's published package can be found here at NPM:

npm install @panoraexchange/swap-sdk

Usage

1. Importing the libraries and creating an instance

//Importing the library
import Panora from "@panoraexchange/swap-sdk"

//Creating a new instance
//apiKey is the API Key provided by the company
const client = new Panora({
apiKey : 'Your API key'
});

2. Swap Functions

Panora provides two functions to perform the swap

  • ExactInSwap: When fromTokenAmount is entered, this function executes and returns the maximum toTokenAmount that will be received.

  • ExactOutSwap: When toTokenAmount is entered, this function executes and returns the minimum fromTokenAmount that has to be paid.

i. ExactInSwap:

//Below is an example to call the function
//ExactInSwap expects two parameters - one is an object with all the fields neccessary for swap and other is the Wallet Private Key
const example = async ()=>{
    const response = await client.ExactInSwap({
        "fromTokenAddress": "0x1::aptos_coin::AptosCoin",
        "toTokenAddress": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
        "fromTokenAmount": 10.5,
        "toWalletAddress":'YOUR WALLET ADDRESS',
    }, 'YOUR PRIVATE KEY')
}

ii. ExactOutSwap:

//Below is an example to call the function
//ExactOutSwap expects two parameters - one is an object with all the fields neccessary for swap and other is the Wallet Private Key
const example = async ()=>{
    const response = await client.ExactOutSwap({
        "fromTokenAddress": "0x1::aptos_coin::AptosCoin",
        "toTokenAddress": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
        "toTokenAmount": 100,
        "toWalletAddress":'YOUR WALLET ADDRESS'
    }, 'YOUR PRIVATE KEY')
}

3. Quote Functions

Panora provides two functions to get the quotes:

  • ExactInSwapQuote: When fromTokenAmount is entered, this function informs the maximum toTokenAmount that will be received.

  • ExactOut SwapQuote: When toTokenAmount is entered, this function informs the minimum fromTokenAmount that has to be paid.

i. ExactInSwapQuote

//Below is an example to call the function
//ExactInSwapQuote expects one parameter which is an object with all the fields neccessary for swap
const example = async ()=>{
    const response = await client.ExactInSwapQuote({
        "fromTokenAddress": "0x1::aptos_coin::AptosCoin",
        "toTokenAddress": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
        "fromTokenAmount": 10.5,
    });
}

ii. ExactOutSwapQuote

//Below is an example to call the function
//ExactOutSwapQuote expects one parameter which is an object with all the fields neccessary for swap
const example = async ()=>{
    const response = await client.ExactOutSwapQuote({
        "fromTokenAddress": "0x1::aptos_coin::AptosCoin",
        "toTokenAddress": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
        "toTokenAmount": 100,
    });
}

Last updated