UNPKG

tegro-swap-sdk

Version:

SDK for building applications on top of Tegro.ag - Swap Aggregator on TON 💎.

76 lines (51 loc) • 2.48 kB
# Tegro Swap SDK This SDK is designed for building applications - Swap Aggregator on TON blockchain 💎. ## Installation You can install the Tegro Swap SDK using either npm or Yarn: **Using npm:** ```shell npm install tegro-swap-sdk ``` **Using Yarn:** ```shell yarn add tegro-swap-sdk ``` ## Integrate Your dApp ### Example: Swapping 1.35 TON to USDT ```typescript import {getAssetsList, getBestRoute, toNano} from 'tegro-swap-sdk'; // 1. Load the list of available tokens const assetsList = await getAssetsList({ userAssets: [] // Array of asset addresses the user holds; see AssetsListParams for more details. }); // Retrieve specific assets by their address const inputAsset = assetsList.find(asset => asset.address === 'ton'); const outputAsset = assetsList.find(asset => asset.address === 'EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'); // 2. Load the best swap route and swap messages const bestRouteResponse = await getBestRoute({ inputAssetAmount: toNano('1.35', inputAsset.decimals).toString(), // Convert 1.35 TON to nano format inputAssetAddress: inputAsset.address, outputAssetAddress: outputAsset.address, senderAddress: 'UQDGGjjuwhikx8ZPJsrLbKXGq7mx26D8pK_l8GqBejzB52Pa', // Optional user wallet address; if set, swap messages will be returned partnerId: 'demo-partner' // Optional unique identifier in our App Developer Partnership program }); // 3. Sign and send messages to the blockchain to execute the swap. // This example uses the React UI client. For other frameworks, refer to https://docs.ton.org/develop/dapps/ton-connect/overview import {useTonConnectUI} from '@tonconnect/ui-react'; const [tonConnectUI] = useTonConnectUI(); const result = await tonConnectUI.sendTransaction({ validUntil: Math.floor(Date.now() / 1000) + 60, // 60 seconds from now 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. ```typescript import {getAppStatus} from 'tegro-swap-sdk'; const { isSwapsEnabled, // true if everything is working fine message // Explanation of why swaps are disabled, if applicable } = await getAppStatus(); ``` ## License This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.