I try to swap coins on QuickSwap for this i use the quickswap-sdk and the ethers
In the following exapmle i want to swap 0.05 Matic to Sand I am this to get the amount of tokens i want to swap:
const qs = require('quickswap-sdk') const ethers = require('ethers') const alchemy = 'https://polygon-mainnet.g.alchemy.com/v2/OfATG5uHb8ZdFbaCLfD79M236-hICOPz' provider = new ethers.providers.JsonRpcProvider(alchemy) wMaticAddress = '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270' mSandAddress = '0xBbba073C31bF03b8ACf7c28EF0738DeCF3695683' matic = await qs.Fetcher.fetchTokenData(137, wMaticAddress, provider) sand = await qs.Fetcher.fetchTokenData(137, mSandAddress, provider) pair = await qs.Fetcher.fetchPairData(matic, sand, provider) route = new qs.Route([pair], sand) //how much is sand in matic price = route.midPrice.toSignificant(6) //Parameter are Decimal Points //Swap Matic to Sand on Quick Swap amountSand = 0.05 amountMatic = amountSand * price console.log(amountSand) console.log(amountMatic)
If i use this sdk i get the following back: 0.05 0.101302
But if i type 0.05 on https://quickswap.exchange/#/swap i get:
This is a different value given by the quickswap Interface and the quickswap-sdk
How do i solve this i dont want to swap my tokens cheaper than needed and if i try to sell them for the calculated price 0.101302 its not working because this is not correct and will not be accepted by quickswap. Any idea how why this accoures and how to solve?