Skip to main content

Swap

Supported Networks for swap

Currently our SDK supports the following networks for the swap functionality and more will be added:

  • Ethereum: Mainnet
  • Polygon: Mainnet
  • Avalanche: Mainnet
  • Arbitrum: Mainnet

We currently support cross-chain evm swaps for: Polygon, Ethereum, Avalanche, Arbitrum

swap(swapRequest: SwapRequest, pkOrProvider: string | ExternalProvider, isGasless: boolean)

The swap() function takes the private key string or the ExternalProvider (if you are using injected provider this type can be imported from import { ExternalProvider } from "@ethersproject/providers"; ) and an object that we call SwapRequest and it has the following object properties:

interface SwapRequest {
srcChainId: number;
srcChainTokenIn: string;
srcChainTokenInAmount: string;
dstChainId: number;
dstChainTokenOut: string;
dstChainTokenOutRecipient: string;
}
NameTypeDescriptionExample
srcChainIdnumberspecifies the chain id as the chain swap is being initiatedethereum mainnet 1
srcChainTokenInstringspecifies the token addressUSDT 0xdAC17F958D2ee523a2206206994597C13D831ec7
srcChainTokenInAmountstringspecifies the desired input amountsince USDT token contract uses 6 decimals (the number of digits that come after the decimal place when displaying token values on-screen), the simple math: 50 * 10^6 leads to 50000000 as the value representing 50 USDT tokens
dstChainIdstringspecified the chainId as the target (destination) chainPolygon network chain id (137)
dstChainTokenOutstringspecifies the address of the target tokensince MATIC is not a typical ERC-20 token represented by a smart contract but rather a native coin (a one-of-a-kind token within each EVM chain), we use a null (or zero) address to distinguish it from other tokens.
dstChainTokenOutRecipientstringthe address target tokens should be transferred to after the swap