⛏️executeSwap

Description

The executeSwap function enables token swaps between two chains using a third-party API.

It takes in the user's private key, source/destination chain, tokens, amount, receives address and slippage as input and returns the transaction receipt for the swap.

Parameters

Name
Type
Description

privateKey

string

The private key of the user's wallet for the source chain

srcChain

string

The name of the source blockchain network (e.g., ETH, AVA, BSC, Polygon, Klaytn), and all specified networks are on the mainnet.

destChain

string

The name of the destination blockchain network (e.g., ETH, AVA, BSC, Polygon, Klaytn), and all specified networks are on the mainnet.

fromToken

string

The address of the token to be swapped on the source blockchain

toToken

string

The address of the token to receive on the destination blockchain

amount

string

The amount of the token to be swapped (in the smallest unit)

receiveAddress

string

The address to receive the swapped tokens on the destination chain

slippage

string

The acceptable slippage rate (in percentage)

Response

Property
Type
Description

Promise<Object>

object

The receipt of the transaction after the token swap is done

Example Request and Response

Prerequisites

Before making requests with Volary SDK, you must have it installed.

You can install Volary SDK using either npm or yarn. Use the following commands to install Volary SDK:

Request

Here is an example of how to make a executeSwap request using the Volary SDK:

Response

Use Cases

  • Cross-chain token swaps: The executeSwap function can be used by decentralized exchanges to facilitate cross-chain token swaps, allowing users to trade their tokens across different blockchain networks.

  • Liquidity providers: The function can also be used by liquidity providers to move their funds across different chains and earn higher yields.

Last updated