# SDK

## 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

```javascript
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. Default is no 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.*&#x20;

### 2. Swap

Fetches a swap quote and executes the transaction on-chain in a single step. Use this when you want to trigger end-to-end transaction without fetching or managing quotes separately. Refer [API page](https://docs.panora.exchange/developer/swap/api) for all available query parameters&#x20;

#### i.  ExactInSwap:

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

#### ii. ExactOutSwap:

```javascript
const exactOutSwap = async () => {
  const response = await panora.swap({
    params: {
      chainId: "1",
      fromTokenAddress:
        "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
      toTokenAddress: "0xa",
      toTokenAmount: "10.5",
      toWalletAddress: "YOUR WALLET ADDRESS",
      slippagePercentage: "1",
      integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
      integratorFeePercentage: "1",
    },
    private_key: "YOUR_PRIVATE_KEY",
  })
}
```

### 3. Quote & Execute

#### a. Quote: Returns quote for a swap transaction. Contains transaction data that can be used to build, sign and submit directly

#### i. ExactInSwapQuote

```javascript
const exactInSwapQuote = async () => {
  const response = await panora.getQuote({
    params: {
      chainId: "1",
      fromTokenAddress:
        "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
      toTokenAddress: "0xa",
      fromTokenAmount: "100",
      toWalletAddress: "YOUR WALLET ADDRESS",
      slippagePercentage: "1",
      integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
      integratorFeePercentage: "1",
    },
  });
};

```

#### ii. ExactOutSwapQuote

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

```

#### b. Execute Quote: Executes a transaction using a pre-fetched swap quote. Unlike swap function, this function does not fetch the quote itself. Use getQuote function to fetch a swap quote.

```typescript
const quoteResponse = await panora.getQuote({
  params: {
    chainId: "1",
    fromTokenAddress:
      "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
    toTokenAddress: "0xa",
    toTokenAmount: "10.5",
    toWalletAddress: "YOUR WALLET ADDRESS",
    slippagePercentage: "1",
    integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
    integratorFeePercentage: "1",
  },
});

const txResponse = await panora.executeQuote({
  quote: quoteResponse,
  privateKey: "YOUR_PRIVATE_KEY"
});

```

### 4. Get Balances

Fetch wallet balances

```typescript
const response = await panora.getBalances({
  walletAddress: "YOUR WALLET ADDRESS",
});
```

### 5. Get Tokenlist

Fetch Panora's Aptos Token List

```tsx
const response = await panora.getTokenList()
```

### 6. Get Prices

Fetch Token Prices

```typescript
const response = await panora.getPrices({
  tokenAddress: ["0xa"],
});

```

## Attribution

Kindly include proper attribution when using the SDK in projects or presentations. Mention “Powered by Panora” wherever applicable.
