3️⃣3️⃣ Request Route & Execute Swap
Before making a swap, you need to request the best route from the SwapKit API.
To request possible routes, follow the instructions below.
Step 1: Build a QuoteParams object
The QuoteParams
object describes a swap to/from any of the supported blockchains and contains all information necessary to determine the best routes. It is defined by the following interface:
The buyAsset
& sellAsset
must be of the format 'chain.ticker'
For example, BTC.BTC
.
The recipientAddress must be a valid address for the buyAsset
blockchain. Similarly the senderAddress must be a valid address for the sellAsset
.
Step 2. Call getQuote from SwapKitApi package
After creating the quoteParams
object, you can pass it to the getQuote
function of the SwapKitApi
class.
Step 3: Choose fee option multiplier, route & execute swap
The skClient
used above assumes a wallet has been connected as described in Set up the SDK.
Executing ERC20 Swaps with tokens on EVM chains need approval spending. Check if asset has been approved with built in methods.
Last updated