Perform Swap
Example: Swapping TON for tsTON
1. Import modules & Initialize SDK
import { TorchSDK, generateQueryId, SwapParams, toUnit } from '@torch-finance/sdk';
import { Asset } from '@torch-finance/core';
const sdk = new TorchSDK();2. Define Swap Parameters
// recommend to generate queryId for every actions
const queryId = await generateQueryId();
// Define assets
const tonAsset = Asset.ton();
const tsTONAsset = Asset.jetton("EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav");
// TON has 9 decimals
const assetInDecimals = 9;
// Define the swap
const swapParams: SwapParams = {
mode: 'ExactIn',
queryId: queryId,
assetIn: tonAsset,
assetOut: tsTONAsset,
amountIn: toUnit('0.01', assetInDecimals), // 0.01 TON
slippageTolerance: 0.01, // 1%
};3. Preview the Swap
4. Execute the Swap
4.1 Execute Swap with Simulation Result
4.2 Execute Swap Directly with Swap Params
Last updated