Rainbow Swap ๐ SDK
This SDK is designed for building applications on top of Rainbow.ag - Swap Aggregator on TON blockchain ๐.
To receive your partnerId
, set custom fees, and enjoy a 50% revenue share, contact us in our Community Chat.
Installation
You can install the Rainbow Swap SDK using either npm or Yarn:
Using npm:
npm install rainbow-swap-sdk
Using Yarn:
yarn add rainbow-swap-sdk
Integrate Your dApp
Example: Swapping 1.35 TON to USDT
import {getAssetsList, getBestRoute, toNano} from 'rainbow-swap-sdk';
const assetsList = await getAssetsList({
userAssets: []
});
const inputAsset = assetsList.find(asset => asset.address === 'ton');
const outputAsset = assetsList.find(asset => asset.address === 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs');
const bestRouteResponse = await getBestRoute({
inputAssetAmount: toNano('1.35', inputAsset.decimals).toString(),
inputAssetAddress: inputAsset.address,
outputAssetAddress: outputAsset.address,
senderAddress: 'UQDGGjjuwhikx8ZPJsrLbKXGq7mx26D8pK_l8GqBejzB52Pa',
partnerId: 'demo-partner'
});
import {useTonConnectUI} from '@tonconnect/ui-react';
const [tonConnectUI] = useTonConnectUI();
const result = await tonConnectUI.sendTransaction({
validUntil: Math.floor(Date.now() / 1000) + 60,
messages: bestRouteResponse.swapMessages
});
Application Status Check
You may want to check the status of your application to ensure everything is functioning correctly. For example, temporarily disable swaps if block production on TON is disrupted due to an external event like the DOGS listing.
import {getAppStatus} from 'rainbow-swap-sdk';
const {
isSwapsEnabled,
message
} = await getAppStatus();
Live Example
For a live example of using the SDK, visit the Rainbow Swap ๐ Repository.
Contact
For questions and suggestions, visit Community Chat.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.