[Ethereum] Check valid slippage before sending transaction using web3

bscpancakeswapweb3js

I have a web3 script that buys and sells the token on Binance Smart Chain (BSC). Now let's say there is a token that has mentioned a mandatory 10% fee in their contract but I don't know about that at the time of swapping. Now if you perform a swap operation from pancakeswap with a slippage of 2% only, it will show an error message that something is wrong with your swap. This error is thrown before even sending the transaction. So I need to achieve a similar feature with my web3.js script. Any help is much appreciated.

Best Answer

Currently, ERC-20 tokens do not expose interface expose transaction fees. Only thing you can find these out is by checking them by hand.

Also, taking fee on transfer() does not fit to ERC-20 token model well at all. Usually the only tokens that do so are some sort of scam tokens from anon fly by the night teams, so my personal recommendation is stay away from all of them.

Related Topic