I want to find buy/sell tax for a given erc20 token sorta like how honeypot.is is able to give that information.

To do this I am simulating a swap on hardhat. The only problem is I am unable to find how many token I actually revived. How can I find how many tokens I actually revived?

And when doing getAmountsOut, amounts[1] is not equal to the amount of token I see in metamask. Im assuming because of the buy tax im reviving less token that what is expected.

Or is there another way I can find buy and sell tax for a given token address?

  • what about calling the balanceOf function to get your own token balance? or can you only simulate one single transaction at a time?
    – user253751
    Apr 19, 2023 at 10:14

1 Answer 1


You can use the following steps to calculate tax:

Get the current price of the token using a Dex like Uniswap by calling the getAmountsOut function on the Uniswap router contract, pass in the amount of ETH you want to swap for token, and the addresses of the token and ETH. This gives you the expected amount of tokens you will receive for the swap, containing any slippage and fees.

do the swap on the DEX, either by calling the swapExactETHForTokens function on router contract or using MetaMask. Calculate the tax by subtracting the actual amount of tokens received from the expected amount of tokens based on the price. lets say, if you expected to receive 100 tokens based on the price, but only received 80 tokens, the tax would be 20%.

Now to find out how many tokens you actually received when simulating a swap on Hardhat, you can use the getAmountsOut function as well. This function returns an array of token amounts, with second element being the expected amount of tokens received for the swap. This value should match the actual amount of tokens you receive after simulating the swap.

If the value of amounts[1] returned by getAmountsOut is not equal to the amount of tokens you see in MetaMask after the swap, it is may be that the difference is due to network fees or slippage. To calculate the actual tax, you will need to use the actual amount of tokens received and compare it to the expected amount based on the price.

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.