π₯οΈ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 = {
panoraApiKey: "PANORA_API_KEY", // Optional. Default is Panora's public api key
geomiApiKey: "GEOMI_API_KEY", // Optional. AKA Aptos Build Api Key. Takes higher priority over rpcUrl
rpcUrl: "CUSTOM_RPC_URL", // Optional
}
const panora = new Panora(config)
Public API Key:
a4^KV_EaTf4MW#ZdvgGKX#HUD^3IFEAOV_kzpIE^3BQGA8pDnrkT7JcIy#HNlLGi
Note: This API key's limits should be sufficient for most use cases. Protocols within the Aptos ecosystem with specific requirements or customization may submit a ticket on Discord.
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.
Last updated