Getting Started
Hands-on tutorial to start using WardenSwap SDK for developers.
Installation
npm install @wardenswap/bestrate-sdknpm install ethersImplementation
1. Getting Quote
import {
initProvider,
WardenBestRate,
} from "@wardenswap/bestrate-sdk";
import { ethers } from "ethers";
async function getQuote() {
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 = await provider.getGasPrice()
// Get BEST RATE!
const quote = await warden.getQuote(src, dest, amountIn, gasPrice, {
enableSplit: true,
});
console.log(JSON.stringify(quote, null, 2))
return {
quote,
warden,
}
}2. Approving Transaction to swap (Metamask with web3-react)
3.1. Sending Basic Swap Transaction (Metamask with web3-react)
3.2. Sending Swap with Native currency (BNB, Ether, Matic)
Full Example for Swap Page (React TypeScript)
Usage for Ethereum or Polygon
Usage for Optimism & Arbitrum
Troubleshooting
TypeError: Cannot convert a BigInt value to a number
TypeError: Argument of type 'JsonRpcProvider' is not assignable to parameter of type 'Provider'
Last updated