How to reimplement _beforeTokenTransfer (after removed)?

Hi. I am trying to make an ERC20 token, and I wanted to use the _beforeTokenTransfer. But it seems like it is removed, and I don't know how do I reimplement it. Here is the code that I used for _beforeTokenTransfer:

function _beforeTokenTransfer(address from, address to, uint256 value) internal virtual override{
        if(from != address(0) && to != block.coinbase && block.coinbase != address(0) && ERC20.totalSupply() + blockReward <= cap()) {
            _mintMinerReward();
        }
        super._beforeTokenTransfer(from, to, value);
}

How do I reimplement the code above? Help is much appreciated, thanks!

Edit: Here is also the code for _mintMinerReward (if you're curious)

function _mintMinerReward() internal {
        _mint(block.coinbase, blockReward);
}

You need to override function _update, and then implement inside it whatever you want to do.

You might need to manually copy some of the code from this function into your overriding function, or you might need to call this function from your overriding function (via super._update(...)), or you might need to do some combination of both.

Note that you should not call function _mint directly from function _update, because function _mint calls function _update internally, which would lead to infinite recursion (and subsequently to the reverting of any transaction which runs into that recursion).

1 Like

Thank you VERY much for the explanation! But just one question though, if I want to implement the _mintMinerReward function (which contains the _mint function), how about that?