I am using swapExactETHForTokens and swapExactTokensForETH with Node.js. But swapExactETHForTokens is working well but swapExactTokensForETH faced error.
(node:13216) UnhandledPromiseRejectionWarning: Error: Returned error: execution reverted: UniswapV2: K
at Object.ErrorResponse (E:\blockchain\token-bot-jav\node_modules\web3-core-helpers\lib\errors.js:28:19)
at E:\blockchain\token-bot-jav\node_modules\web3-core-requestmanager\lib\index.js:300:36
at E:\blockchain\token-bot-jav\node_modules\web3-providers-http\lib\index.js:124:13
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
Here is my code. And already approved in other function.(Uniswap_router_address:
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
)
Try using swapExactTokensForETHSupportingFeeOnTransferTokens
and swapExactETHForTokensSupportingFeeOnTransferTokens
.
The K
error means that the x*y=k
invariant gets broken as a result of the swap. This may happen because these are fees-on-transfer or other type of exotic tokens. The functions above can deal with that.