ERC-20 can't get transferFrom function to work on Remix

I am testing my ERC-20 token in Remix on the virtual machines. The transfer function works, but I cannot get the transferFrom function to work, it keeps throwing "ERC20: transfer amount exceeds allowance". As address A in the VM, I have approved B to transfer to address C. I increased allowances and even checked the allowance function for address B but I still cant get this function to work.

:1234: Code to reproduce

// SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.10;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
//-----------------------------------------------------------------------------------------| BEGIN CONTRUCTOR AND STATE VARIABLES
contract ElonGatoMarsTest is ERC20 {

    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply = 1000000000000 * (10 ** 18);
    uint256 private _minimumSupply = 69420000 * (10 ** 18);
    string private _symbol = "EGMT";
    string private _name = "EGMTTest";

    constructor() ERC20("ElonGatoMarsTest", "EGMT") {
        _mint(msg.sender, 1000000000000 * (10 ** 18));
    }
//-----------------------------------------------------------------------------------------| END CONSTRUCTOR, BEGIN BURN LOGIC
    function calculateBurnAmount(uint256 amount) private view returns (uint256) {
        uint256 burnAmount = 0;
        if (_totalSupply > _minimumSupply) {
            burnAmount = (amount / 20);
        }
        return burnAmount;
    }
//-----------------------------------------------------------------------------------------| END BURN LOGIC, BEGIN BURN IMPLEMENNTATION
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        uint256 amountToBurn = calculateBurnAmount(amount);
        uint256 amountToTransfer = (amount - amountToBurn);
        _transfer(_msgSender(), recipient, amountToTransfer);
        _burn(msg.sender, amountToBurn);
        assert(_totalSupply >= _minimumSupply);
        return true;
    }
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        uint256 amountToBurn = calculateBurnAmount(amount);
        uint256 amountToTransfer = (amount - amountToBurn);
        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }
        _transfer(sender, recipient, amountToTransfer);
        _burn(sender, amountToBurn);
        assert(_totalSupply >= _minimumSupply);
        return true;
    }
}

:computer: Environment

Is there something wrong with my transferFrom function?

your mapping _balance is not storing any value at the moment of mint, the value is stored in the mapping _balance of the erc20 contract, if you need to make any modification in the transfer functions, modify the erc20 contract directly

Could you elaborate a bit more?

My understanding is that when I deploy this code, the constructor function mints all of the tokens to the address under the Virtual Machine in Remix. I confirmed this by calling the balanceOf function of the VM address (NOT the contract address) and it showed all of the tokens. What are you suggesting I change?

I recommend that you spend all your programming logic, the erc20 contract would be the best option for your problem

Hello,

Yes I am inheriting from the ERC20 OpenZeppelin standard.

I just tried the transferFrom function on a blank ERC20 template where I removed everything below the constructor you see above and it worked. Something is wrong with the functions that is preventing the transferFrom function from working. I suspect it may be the assert statements.

Excuse me, if I don't explain it well, if you want to modify the transfer functions you have to do it directly in the erc20 contract, not in your ElonGatoMarsTest contract

Okay, so I need to flatten the contract, and then modify the functions in the parent contract?

if you need to flatten the contract and then create your transfer logic in the erc20 contract :smiling_face_with_three_hearts:, let me know if my help worked for you

Hello, I added the burn logic to the parent ERC20 contract along with the minimumSupply state variable and the transferFrom function works now. Thanks

I'm glad to be able to help you

you can mark the issue as solved, it would be of great help