I`m trying to create token that burns some % of swap amount from liquidity pool every time user buy it.

I tried to implement it including _burn function to _transfer function overriding.

function _transfer(
    address from,
    address to,
    uint256 value
) internal override {
    uint256 toBurn = value * amountToBurn / 100;
    _burn(from, toBurn);
    super._transfer(from, to, value);

amountToBurn - is global variable that keeps precent of tokens i want to burn. For example, 5.
I did it in this way for ability to change it using special function.

This is how burn function look like. As you can see, it`s default ERC20 burn function.

function _burn(address account, uint256 amount) internal virtual {
    require(account != address(0), "ERC20: burn from the zero address");

    _beforeTokenTransfer(account, address(0), amount);

    uint256 accountBalance = _balances[account];
    require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
    unchecked {
        _balances[account] = accountBalance - amount;
        _totalSupply -= amount;

    emit Transfer(account, address(0), amount);

    _afterTokenTransfer(account, address(0), amount);

It works good when i do transfer between two adresses, but when i try to buy/sell it in PancackeSwap(testnet) it returns error:

The transaction cannot succeed due to error: undefined. This is probably an issue with one of the tokens you are swapping.

Maybe it should help you to answer:

  1. It`s able to swap when amountToBurn is equal to 0

  2. This is how burning look like when it was in transaction between 2 addresses(successful) amountToBurn = 5:
    From SenderAddress to 0x00000... For 50 TOKEN
    From SenderAddress to RecepientAddress For 1000 TOKEN

  3. This is how burning look like when it was swaped amountToBurn = 0:
    From PancackeRouter to LiquidityPool For 0.001 BNB
    From LiquidityPool to 0x00000... For 0 TOKEN
    From LiquidityPool to RecepientAddress For 988.382... TOKEN

  4. When swaped, PancackeSwap(testnet) used swapExactETHForTokens() function method:0x7ff36ab5


1 Answer 1


The most obvious reason for the transfers to fail on pancake swap is due to the nature of how swaps happen in erc20 tokens , whenever a swap transaction happens we send token amount as a value to swap such as 100 and when our token contract burns 1 token on transfer pancake swap checks whether the amount is same as user requested to swap but instead of 100 Pancake receives 99 tokens so the transactiion is reverted.

This is just my speculation, i'm gonna test it myself ping me if you have an update or want one.

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.