# Swap Tokens
WX Network provides the Swap tool based on the public smart contract (opens new window) that allows users to instantly exchange tokens in various directions without any amount limitations. The swaps liquidity is provided by the Liquidity pools.
Read more about Swap tool (opens new window).
# How to Swap Tokens
Open WX Network (opens new window) app, login to your account and in the Trading tab select one of the available swap directions, for example USDT/WX (opens new window).
In the I Send field specify the amount to swap. In the I receive field the estimated amount of the token that you will receive will be displayed. The current spot and swap rates will be displayed in the fields below.
Select the appropriate Slippage value and the Transaction Fee token, then click Swap USDT to WX.
# How to Swap Tokens via dApp
It is possible to swap tokens not only via WX Network interface, but also via Waves dApp. This functionality might be useful for bot developers and any advanced users in general.
In the following example lets review a swap of 1 USDT to XTN with 5% slippage.
The Swap dApp works with exact numbers, so, first of all, you will need to figure out the amount that you want to swap based on the current swap rate.
To do so, navigate to Waves node POST /utils/script/evaluate/{address} (opens new window) swagger interface:
Long story short, you need to ask the contract to evaluate how much XTN will be received for a swap of 1 USDT.
Request example:
{
"expr": "swapCalculateREADONLY(1000000,\"34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ\",\"DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p\")"
}
Where:
3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93 is the Swap dApp address.
1000000 is the amount of the sent token (1 USDT).
34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ is the ID of the sent token (USDT).
DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p is the ID of the received token (XTN).
Response example:
{
"result": {
"type": "Tuple",
"value": {
"_1": {
"type": "Array",
"value": []
},
"_2": {
"type": "Int",
"value": 4192129
}
}
},
"complexity": 3569,
"expr": "swapCalculateREADONLY(1000000,\"34N9YcEETLWn93qYQ64EsP1x89tSruJU44RrEMSXXEPJ\",\"DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p\")",
"address": "3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93"
}
Where:
4192129 is the value you are looking for. It indicates that at the current swap rate 1 USDT can be swapped to 4,192129 XTN. The Service Fee is already deducted from this value.
Before executing the swap, calculate and deduct the slippage amount.
For example, multiply the value by 0.95 to quickly deduct 5% slippage:
4192129x0.95=3982522
Now that you know the exact amount based on the current swap rate and 5% slippage, navigate to the dApp page (opens new window), login to your account and input the Swap contract address (3P68zNiufsu1viZpu1aY3cdahRRKcvV5N93).
In the amountOutMin field enter the 3982522 amount.
In the assetOut field enter the ID of XTN (DG2xFkPdDwKUoBkzGAhQtLpSGzfXLiCYPEzeKH2Ad24p).
In the addressTo field enter the address that will receive XTN.
Click Attach payment.
Select USDT from the list and specify the 1.000000 amount.
Click Invoke.
In the window that opens, confirm the transaction.
See more articles in the Token Management chapter.
If you have difficulties with WX Network, please create a support (opens new window) ticket or write a question on our forum (opens new window).