> For the complete documentation index, see [llms.txt](https://docs.panora.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.panora.exchange/developer/sdk_gasless.md).

# SDK\_GASLESS

## 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. 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.*&#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. Gasless Transactions

Trigger swap transactions with fee-payer enabled, allowing another account to cover the network gas fees by sponsoring the transaction.

Fetch swap quote

<pre class="language-typescript"><code class="lang-typescript"><strong>const quote = await panora.getQuote({
</strong>  params: {
    chainId: "1",
    fromTokenAddress:
      "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b",
    toTokenAddress: "0xa",
    fromTokenAmount: "100",
    toWalletAddress: "YOUR WALLET ADDRESS",
    slippagePercentage: "1",
    integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
    integratorFeePercentage: "1",
    // Builds and returns the raw transaction of the payload
    getRawTransaction: true,
  },
  // Builds the transaction with fee payer enabled
  withFeePayer: true,
});
</code></pre>

Retrieve fee payer account

```typescript
// Using private key
const formattedPrivateKey = PrivateKey.formatPrivateKey(
  "YOUR PRIVATE KEY",
  PrivateKeyVariants.Ed25519
);
const privateKey = new Ed25519PrivateKey(formattedPrivateKey);
const feePayerAccount = Account.fromPrivateKey({ privateKey });
const feePayerPublicKey = feePayerAccount.publicKey;

// Using Account.generate()
const feePayerAccount = Account.generate()
const feePayerPublicKey = feePayerAccount.publicKey;
```

Sign the raw transaction as fee payer

```typescript
// Using raw transaction from quote response
// This will only be present when 'getRawTransaction' is set to true
const rawTransaction = quote?.quotes?.[0].rawTransaction;

// Sign the transaction with the fee payer account
const feePayerAuthenticator = aptos.transaction.signAsFeePayer({
  signer: feePayerAccount,
  transaction: rawTransaction,
});

// By building the response payload
const txData = quote.quotes?.[0].txData;
const paylod = {
  function: txData?.function,
  typeArguments: txData?.type_arguments,
  functionArguments: txData?.arguments,
};

const rawTransaction = await aptos.transaction.build.simple({
  sender: "YOUR WALLET ADDRESS",
  data: paylod,
  withFeePayer: true,
});

const feePayerAuthenticator = aptos.transaction.signAsFeePayer({
  signer: feePayerAccount,
  transaction: rawTransaction,
});
```

Execute  gasless swap transaction

```typescript
const executeQuoteResponse = (await panora.executeQuote({
  quote,
  privateKey: "YOUR PRIVATE KEY",
  getTxInfo: true,
  feePayerSig: feePayerAuthenticator,
  isSimulationEnabled: true,
  // By default the transaction is simualted without a fee payer. Adding this will ensure that feePayer has sufficient balance to cover the gas fee for the transaction.
  feePayerPublicKey,
})) as SwapTxResponseWithStatus;

console.log("Transaction Response", executeQuoteResponse);
```

Gasless Transactions Code Sample

```typescript
import {
  Account,
  Ed25519PrivateKey,
  PrivateKey,
  PrivateKeyVariants,
} from "@aptos-labs/ts-sdk"
import { SwapTxResponseWithStatus } from "@panoraexchange/swap-sdk"

const gasless = async () => {
  const quote = 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",
      getRawTransaction: true,
    },
    withFeePayer: true,
  })

  const formattedPrivateKey = PrivateKey.formatPrivateKey(
    "YOUR PRIVATE KEY",
    PrivateKeyVariants.Ed25519
  )

  const privateKey = new Ed25519PrivateKey(formattedPrivateKey)
  const feePayerAccount = Account.fromPrivateKey({ privateKey })
  const feePayerPublicKey = feePayerAccount.publicKey

  const rawTransaction = quote?.quotes?.[0].rawTransaction

  const feePayerAuthenticator = aptos.transaction.signAsFeePayer({
    signer: feePayerAccount,
    transaction: rawTransaction,
  })

  const executeQuoteResponse = (await panora.executeQuote({
    quote: quote,
    privateKey: "YOUR PRIVATE KEY",
    getTxInfo: true,
    feePayerSig: feePayerAuthenticator,
    isSimulationEnabled: true,
    feePayerPublicKey,
  })) as SwapTxResponseWithStatus

  console.log("Transaction Response", executeQuoteResponse)
}
```

### 5. Get Balances

Fetch wallet balances

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

### 6. Get Tokenlist

Fetch Panora's Aptos Token List

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

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