You could read this guide to understand the flow of integrating Rango-Basic-SDK. If you prefer to dive directly into the code and explore it there, you can use the links below.
To get the list of available blockchains, tokens, and protocols (dex or bridge) supported by Rango, you could use the meta method like this:
constmeta=awaitrango.meta()
Get Quote
Using information retrieved from the meta, you could implement your own SwapBox including your blockchain and token selector. The next step is to show the preview of the best route possible when the user selects the source and the destination tokens.
The blockchain and symbol names must be exactly what is fetched from Rango's Meta API.
// Converting 0.1 BSC BNB to AVAX_CCHAIN USDT.E constquote=awaitrango.quote({ from: {"blockchain":"BSC","address":null }, to: {"blockchain":"AVAX_CCHAIN","address":"0xc7198437980c041c805a1edcba50c1ce5db95118" }, amount:"100000000000000000"})
You could call this method periodically to get the updated route before the user confirms the swap.
Creating Transaction
Whenever the user decides to accept the quote and submit the swap, you should call the SDK swap method to get the latest route and transaction data needed to proceed.
// Swap 0.1 BSC BNB to AVAX_CCHAIN USDT.E constquote=awaitrango.swap({ from: {"blockchain":"BSC","address":null }, to: {"blockchain":"AVAX_CCHAIN","address":"0xc7198437980c041c805a1edcba50c1ce5db95118" }, amount:"100000000000000000", fromAddress:"0xbe807dddb074639cd9fa61b47676c064fc50d62c", toAddress:"0xbe807dddb074639cd9fa61b47676c064fc50d62c", slippage:1.5, disableEstimate:false, referrerAddress:null,// your dApp wallet address for referral referrerFee:null,// your dApp desired referral fee percent })
The route field in response is similar to what you've seen in the quote section and the tx field section is the data of the transaction that needed to be passed to the proper wallet to be signed by the user.
Tracking Swap Status
After signing the transaction by the user and receiving transaction hash, you could periodically call Rango check-status API to track the transaction status. In Rango, each swap step could have 3 different states: running, failed and success. You only need to keep checking the status until you find out whether the transaction failed or succeeded.
Here's a sample request for the check-status API, along with the corresponding response it receives: