2

I'm trying to find out if there is a way programmatically (using web3) to check if a token takes a fee on transfer, such as the ones that require the swapExactETHForTokensSupportingFeeOnTransferTokens function on the Uniswap router.

Is it possible to discover this information without having to call the Uniswap swapExactETHForTokens function and subsequently checking for the infamous "UniswapV2: K" errors?

3 Answers 3

4

I've been trying to figure this out as well. The only thing I've seen, would be pretty hacky, but you could parse through some of the latest transactions with that token, and see how many internal transactions they generate.

enter image description here

For instance, this is what a transaction looks like when the token has some sort of burn or fee on transfer functionality. Every transaction using this token would have at least three internal transfers. But a token without any FoT or burn would mostly have transactions with two internal transfers. You'd have to parse a good number of them to be sure. But that is one (really ugly) way you could do it.

Additionally, somebody could maybe just make a token list with a curated set of data about fee on transfers.

3

I have seen lots of tokens with different dynamics to get some fee. Some wallets are even exempt from paying those fees giving false positives in the analysis.

What works for me in python using web3.py: I make a fake transaction and execute it locally using the eth.estimate_gas function. If it raises an exception it will give you a solidity error that, if your code and transaction parameters are all right, will mean the token is not a normal one.

0

Ok, I can think of one way with only one drawback. You will need some of the token to check. This is only theoretically because I did not test it but I assume it has to work.

Steps to test

  1. Use 2 wallet addresses (One has to be empty the other one holds the token)
  2. Write an Contract that does the following
    1. Get the approval to transfer the token
    2. Transfer x tokens from one address to the other
    3. return the balance of the token now in the target address
  3. !IMPORTANT! Call the contract with CallStatic to handle the function like an view function. The contract will execute the transfer but not manipulate the blockchain, it will cost 0 gas and it will return the balance that would have been moved to the second address.
  4. Compare your input amount with the balance returned. If the balance is lower then there is a fee on transfer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.