Panora
  • πŸ‘‹Welcome to Panora
  • 🌐Official Links
  • PRODUCT SUITE
    • πŸ’±Panora Swap
    • πŸ“ŠPanora Trade
  • Developer
    • πŸ’»Swap Widget
      • Install Widget
      • Widget Configuration
      • Theme Customization
      • Widget Controls
      • Guide
    • πŸ€–Swap API & SDK
      • πŸ’»Swap API
        • Examples
      • πŸ–₯️Swap SDK
      • πŸ’¦Supported Sources
    • 🎞️Swap iframe
    • πŸͺ™Token List
      • πŸ“”How to Add Your Token to the Panora Token List
    • πŸ’²Token Prices
  • PARTNERSHIPS
    • 🀝Become Our Partner
    • 🏒Media & Brand Kit
  • FAQs
    • ❓Panora Help
  • LEGAL
    • πŸ—’οΈLegal Disclaimer
    • πŸ”“Brand & Logos
    • πŸ“Terms of Use
Powered by GitBook
On this page
  • Installation
  • Usage
  • 1. Initialize Panora SDK
  • 2. Swap Functions
  • 3. Quote Functions
  • Attribution
  1. Developer
  2. Swap API & SDK

Swap SDK

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

Installation

Using npm

npm install @panoraexchange/swap-sdk

Using yarn

yarn add @panoraexchange/swap-sdk

Using pnpm

pnpm add @panoraexchange/swap-sdk

Usage

1. Initialize Panora SDK

import Panora, { PanoraConfig } from "@panoraexchange/swap-sdk"

const config: PanoraConfig = {
  apiKey: "YOUR API KEY",
  rpcUrl: "CUSTOM RPC URL"
}

const client = new Panora(config)
  • Public API Key:

    a4^KV_EaTf4MW#ZdvgGKX#HUD^3IFEAOV_kzpIE^3BQGA8pDnrkT7JcIy#HNlLGi

    Note: For large-scale public applications, please submit a ticket on Discord to request a dedicated API key for enhanced performance and reliability.

2. Swap Functions

i. ExactInSwap:

const exactInSwap = async () => {
  const response = await client.Swap(
    {
      chainId: "1",
      fromTokenAddress: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
      toTokenAddress:
        "0xa",
      fromTokenAmount: "100",
      toWalletAddress: "YOUR WALLET ADDRESS",
      slippagePercentage: "1",
      integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
      integratorFeePercentage: "1",
    },
    "YOUR PRIVATE KEY"
  )
}

ii. ExactOutSwap:

const exactOutSwap = async () => {
  const response = await client.Swap(
    {
      chainId: "1",
      fromTokenAddress: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
      toTokenAddress:
        "0xa",
      toTokenAmount: "10.5",
      toWalletAddress: "YOUR WALLET ADDRESS",
      slippagePercentage: "1",
      integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
      integratorFeePercentage: "1",
    },
    "YOUR PRIVATE KEY"
  )
}

iii. BatchSwap:

const exactInSwapBatch = async () => {
  const response = await client.BatchSwap(
    [
      {
        chainId: "1",
        fromTokenAddress: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
        toTokenAddress:
          "0xa",
        fromTokenAmount: "100",
        toWalletAddress: "YOUR WALLET ADDRESS",
        slippagePercentage: "1",
        integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
        integratorFeePercentage: "1",
      },
      {
        chainId: "1",
        fromTokenAddress: "0xa",
        toTokenAddress:
          "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
        fromTokenAmount: "10.5",
        toWalletAddress: "YOUR WALLET ADDRESS",
        slippagePercentage: "1",
        integratorFeeAddress: "INTEGRATOR FEE ADDRESS",
        integratorFeePercentage: "1",
      },
    ],
    "YOUR PRIVATE KEY"
  )
}
// for exactOutSwapBatch use the same approach but instead of fromTokenAmount send the desired toTokenAmount

3. Quote Functions

i. ExactInSwapQuote

const exactInSwapQuote = async () => {
  const response = await client.SwapQuote({
    chainId: "1",
    fromTokenAddress: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
    toTokenAddress:
      "0xa",
    fromTokenAmount: "100",
    toWalletAddress: "YOUR WALLET ADDRESS",
    slippagePercentage: "1",
    integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
    integratorFeePercentage: "1",
    // "rawTransaction" | "transactionPayload" depending on the use case
    getTransactionData: "rawTransaction"
  })
}

ii. ExactOutSwapQuote

const exactOutSwapQuote = async () => {
  const response = await client.SwapQuote({
    chainId: "1",
    fromTokenAddress: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
    toTokenAddress:
      "0xa",
    toTokenAmount: "10.5",
    toWalletAddress: "YOUR WALLET ADDRESS",
    slippagePercentage: "1",
    integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
    integratorFeePercentage: "1",
  })
}

Attribution

Kindly include proper attribution when using the API in projects or presentations. Mention β€œPowered by Panora” wherever applicable.

PreviousExamplesNextSupported Sources

Last updated 15 days ago

πŸ€–
πŸ–₯️