# Overview

### Why WardenSwap SDK?

WardenSwap SDK will be your best way to equip the Best Rate AI power to bring your platform to the next level.&#x20;

![](/files/LHGnc6kqtVyZVKha8EOv)

{% hint style="info" %}
Warden SDK is already available for public use. To participate in the profit sharing program, please submit the form here: <https://forms.gle/qZfiW67SNvRKRL7h8>
{% endhint %}

### Supported Chains

* **Ethereum (Mainnet)**
  * Warden Router Contract: [`0x39f97198c5DbC193EB962c4B3B7e447091A18eAB`](https://etherscan.io/address/0x39f97198c5DbC193EB962c4B3B7e447091A18eAB)
* **Binance Smart Chain**
  * Warden Router Contract: [`0x451ef8D6B645a60115EB8b8bEa76B39C0C761004`](https://bscscan.com/address/0x451ef8D6B645a60115EB8b8bEa76B39C0C761004)
* **Polygon**&#x20;
  * Warden Router Contract: [`0x030B8b7bF245E762736e65c0903295447B898c30`](https://polygonscan.com/address/0x030b8b7bf245e762736e65c0903295447b898c30)
* **Avalanche**
  * Warden Router Contract: [`0x5EF960Eb78B8CFc11e654D03BeEB313BaDF5C7C0`](https://snowtrace.io/address/0x5EF960Eb78B8CFc11e654D03BeEB313BaDF5C7C0)
* **Optimism**
  * Warden Router Contract: [`0x7EA8c22E6Dcd7bd69eb180664Da68e1f1F11D696`](https://optimistic.etherscan.io/address/0x7EA8c22E6Dcd7bd69eb180664Da68e1f1F11D696)
* **Arbitrum**
  * Warden Router Contract: [0x79A556ef2c5b613dB3DFa8797E6772c5AAF86834](https://arbiscan.io/address/0x79A556ef2c5b613dB3DFa8797E6772c5AAF86834)

For testing without using actual tokens, see [Testing](/warden/wardenswap-sdk/testing.md) section.

### Supported Tokens

* [Ethereum Token List](https://tokenlists.org/token-list?url=https://file-utility.wardenswap.finance/tokenlists/ethereum-tokenlists.json)
* [BSC Token List](https://tokenlists.org/token-list?url=https://file-utility.wardenswap.finance/tokenlists/bsc-tokenlists.json)
* [Polygon Token List](https://tokenlists.org/token-list?url=https://file-utility.wardenswap.finance/tokenlists/polygon-tokenlists.json)
* [Avalanche Token List](https://tokenlists.org/token-list?url=https://file-utility.wardenswap.finance/tokenlists/avalanche-tokenlists.json)
* [Arbitrum Token List](https://tokenlists.org/token-list?url=https://file-utility.wardenswap.finance/tokenlists/arbitrum-tokenlists.json)
* [Optimism Token List](https://tokenlists.org/token-list?url=https://file-utility.wardenswap.finance/tokenlists/optimism-tokenlists.json)

### How it works?

Let's say the user want to swap 1,000 BUSD to WAD on your dashboard in Binance Smart Chain

![](/files/LsP8ejG553pwmm609dlV)

You can integrate WardenSwap SDK to help get the quote, then send the swap transaction with normal Web3.js or Ethers.js. So for now the key functionality of the SDK is to get you the best rate quote.

![](/files/RXCi60zQy0ImZFIH1Uao)

1. **Connecting Wallet** can be done with Ethers.js, Web3.js or related libraries.
2. **Approve BUSD** will required user to approve spending by sending the approve transaction to the BUSD contract to be spent by WardenSwap contract. In case the user already approved or swapping BNB, no need for approval.
3. **Get Quote** can be done with WardenSwap SDK, it will return you the `amountOut` which is the full amount of the destination token to display to users. Note that the `amountOut` is the estimated value.
4. **Swap** is when you request user to confirm the swap transaction built from quote response and send to WardenSwap contract with function `swap` or `swapSplit`.

{% hint style="info" %}
After the swap submission, the transaction will be pending. You will need to watch the transaction to see the swap result.
{% endhint %}

### Quick Sample Code: Get Quote & Swap

Here is the minimal sample code for BNB Smart Chain integration to help you understand how to use it quickly.

```javascript
import {
  initProvider,
  WardenBestRate,
} from "@wardenswap/bestrate-sdk";
import { ethers } from "ethers";

async function swapWithWarden() {
  const provider = initProvider("https://bsc-dataseed.binance.org");
  const warden = new WardenBestRate(provider, "bsc");

  const src = "0xe9e7cea3dedca5984780bafc599bd69add087d56"; // source Token Address: BUSD
  const srcDecimals = 18; // source token's decimals
  const dest = "0x0feadcc3824e7f3c12f40e324a60c23ca51627fc"; // destination Token Address: WAD
  const amountIn = ethers.utils.parseUnits("100", srcDecimals); // amount of source token
  const gasPrice = ethers.utils.parseUnits("5", "gwei"); // current gas price

  // Get BEST RATE!
  const quote = await warden.getQuote(src, dest, amountIn, gasPrice, {
    enableSplit: true,
  });

  // Get the signer with private key
  // For using with Metamask, see: https://docs.ethers.io/v5/getting-started/#getting-started--connecting
  // For using other wallet, see: https://docs.ethers.io/v5/single-page/#/v5/api/signer/-%23-Wallet
  const YOUR_PRIVATE_KEY = process.env.PRIVATE_KEY;
  const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider);

  // Specify slippage, which is 1%
  const minDestAmount = ethers.BigNumber.from(quote.amountOut).mul(99).div(100);

  // Allow WardenSwap contract to use token in your wallet to perform swapping
  console.log("Approving token...");
  let tx = await warden.approve(signer, src, amountIn);
  console.log("Tx Hash:", tx.hash);
  await tx.wait();

  // Perform a swap!
  console.log("Swapping...");
  tx = await warden.swap(signer, src, dest, amountIn, minDestAmount, quote);
  console.log("Tx Hash:", tx.hash);
  await tx.wait();
  console.log("Swapped!");
}

swapWithWarden();
```

{% hint style="info" %}
In order to use your own implementation to perform swap, ABI of WardenSwap contract can be found at etherscan links in [Supported Chains](#supported-chains) section.
{% endhint %}

### Available Functions

Available functions can be found in [Reference](/warden/wardenswap-sdk/references.md) Section

{% hint style="info" %}
Address of native currencies e.g. BNB, MATIC, ETH are represented as `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wardenswap.finance/warden/wardenswap-sdk/overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
