简体   繁体   中英

I face Uniswap: K error when I use swapExactTokensForETH function

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM