Help with tax on my contract

I deployed a smart contract on Sepolia test network with tax functions applied. I have it so transfers between wallets will always remain tax free even when tax is applied for buys/sells. I added the pair on uniswap test mode. When I have the tax at 0% I am able to swap eth for the test token and then swap it back again, but when I change the tax to 3% I am able to swap eth for the token but when I try and swap the token to eth it says "this swap may fail" What could be causing this issue please? I have added the tax wallet, contract address as excluded from tax.

Hello @ShadowDev90

I can help you.

Hope discuss further more details via Telegram.

Telegram: @helpcenter15

Best regards.

Hi,

Thank you for sharing the details. Based on your description, the issue likely comes from how the tax logic is applied during sell (token → ETH) transactions, specifically when interacting with the Uniswap pair contract.

When tax is set to 0%, both buy and sell swaps work normally. However, when the tax is set to 3%, the sell transaction reverts with “this swap may fail,” which typically indicates one of the following smart-contract conditions:

Possible Causes

  1. Tax logic interfering with AMM pair operations
    Even if transfers between wallets are excluded from tax, swapping through the pair invokes transferFrom, which may trigger tax deduction.
    If the router or pair contract is not exempted properly, the tax amount may reduce the output token below the expected minimum, causing the transaction to fail.

2) transfer / transferFrom returns amount mismatch

Some tax implementations modify the amount sent, but do not correctly reflect the deducted amount in the return value or event emissions.
If the router expects amountIn but receives less due to tax, it may revert.

3) Insufficient received tokens for liquidity pair

When selling, the pair must receive the full input amount. If tax reduces the transfer amount, the received value becomes less than required, causing price checks (amountOutMin) to fail.

4) Tax applied unintentionally on Uniswap pair

Even if the wallet is excluded, the pair contract itself must also be excluded, otherwise the tax is applied during swaps, making the pair receive insufficient tokens.

You mentioned excluding tax wallet + contract address — please confirm that the Uniswap pair address is also excluded.

5) Re-entrancy or internal require() conditions

Some tax implementations enforce additional checks during sells that may fail depending on timing/flags — especially if you track buy/sell separately.

Recommended Debug Steps

  1. Ensure Uniswap pair address is tax-exempt.

  2. Confirm the transfer() / transferFrom() returns true and handles taxed amounts correctly.

  3. Log values during swap:

    • _amount

    • taxAmount

    • transferAmount

  4. Verify router receives the actual post-tax value.

  5. Temporarily remove tax from sells only to isolate the logic.

Likely Root Cause

Most commonly, the AMM pair is not tax-exempt, so it receives fewer tokens than expected when selling, causing the router to revert due to amountOutMin slippage or failed price calculation.

When buying (ETH → token), the tax is processed differently and doesn’t interfere with the required liquidity balance, which is why buys succeed.

Still you need someone to resolve issues, please connect on telegram @paybankings

Thanks.