Wido Docs
Search…
βš™
Wido Javascript SDK
Integrate Wido SDK into your dApp and offer single-click transactions (Zaps) that route any tokenA into any tokenB, across chains and Layer 2s.
The integration consists of 3 simple steps:
  1. 1.
    Approve Wido Smart Contract for Zap
  2. 2.
    Receive Zap transaction details from the Wido API
  3. 3.
    Execute the Zap transaction from the user's wallet

Preparation: Install Wido SDK using NPM

npm install --save wido

Step 1: Approve Wido for a Zap transaction

In this step, create an approve transaction to allow the Wido Contract to access the token being transferred (the input token).
import { approveForZap } from "wido"
​
const { data, to } = await approveForZap(
{
chainId,
tokenAddress, // Token to approve for Zap.
amount // Amount to allow. It can be left empty for maximum approval.
}
)
​
const tx = await signer.sendTransaction({ data, to })
​
console.log(tx.hash)
// "0x66acd87c5e..."
​
await tx.wait()

Step 2: Receive a Quote

Request a quote for the Zap transaction.
Note: steps object contains details about the transaction route.
import { quote } from "wido"
​
const quoteResult = await quote(
{
fromChainId, // Chain Id of the from token
fromToken, // Token address of from token
toChainId, // Chain Id of the to token
toToken, // Token address of to token
amount, // Token amount of from token
slippagePercentage, // Acceptable max slippage for the swap
user, // Address of user placing the order.
},
provider
)
​
const {
isSupported, // Whether the route is supported or not
steps, // The steps this route will take. Used to show the route breakdown
stepsCount, // Number of steps the route will take
price, // Expected price of `toToken`
minPrice, // Minimum accepted price for a successful transaction
fromTokenUsdPrice, // Price of `fromToken` in US dollars
fromTokenAmount, // Amount of `fromToken` to send
fromTokenAmountUsdValue, // Value of `fromTokenAmount` in US dollars
toTokenUsdPrice, // Price of `toToken` in US dollars
toTokenAmount, // Expected amount of `toToken` to receive
toTokenAmountUsdValue, // Value of `toTokenAmount` in US dollars
expectedSlippage, // Expected slippage calculated from `fromTokenAmountUsdValue` and `toTokenAmountUsdValue`
minToTokenAmount, // Minimum amount of the to token the user is willing to accept for a successful transaction
to, // The contract address where the unsigned transaction needs to be sent
data, // Unsigned transaction data
} = quoteResult
​

Step 3: Execute the Zap transaction

In this step, execute the Zap transaction using data received from calling the quote.
import { quote } from "wido"
​
const { data, to } = await quote(
{
fromChainId, // Chain Id of the from token
fromToken, // Token address of from token
toChainId, // Chain Id of the to token
toToken, // Token address of to token
amount, // Token amount in from token
slippagePercentage, // Acceptable max slippage for the swap
user, // Address of user placing the order.
},
provider
)
​
const tx = await signer.sendTransaction({ data, to })
​
console.log(tx.hash)
// "0x66acd87c5e..."
​
await tx.wait()

List of Supported Tokens

Get the list of supported tokens on all chains or on a specific chain. Zap between any supported token is possible in and across the supported chains.
import { getSupportedTokens } from "wido"
​
const tokenList = await getSupportedTokens(chainId) // If not passed it will return everything
console.log(tokenList)
// [
// {
// address: "0x04068DA6C83AFCFA0e13ba15A6696662335D5B75",
// chainId: 250,
// decimals: 6,
// name: "USD Coin",
// symbol: "USDC",
// },
// ...
// ]
​

List of User Balances

Get the list of supported tokens found in the user's wallet, on all chains or on a specific chain, that can be used for depositing. Zap between any supported token is possible in and across the supported chains.
import { getBalances } from "wido"
​
const balances = await getBalances("0x6568d65a8CB74A21F8cd7F6832E71Ab1E390f25E")
console.log(balances)
// [
// {
// chainId: 137,
// address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
// symbol: "WETH",
// name: "Wrapped Ether",
// decimals: 18,
// logoUri: "https://logos.covalenthq.com/tokens/1/0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.png",
// balance: "3000000000000000",
// balanceUsdValue: "4.08",
// tokenUsdPrice: "1360.97"
// },
// ...
// ]
​
​
Copy link
On this page
Preparation: Install Wido SDK using NPM
Step 1: Approve Wido for a Zap transaction
Step 2: Receive a Quote
Step 3: Execute the Zap transaction
List of Supported Tokens
List of User Balances