0

 /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

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

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

**Additional Question

If a token holder sends token to address(0) or 0x0 , does the supply for that token get automatically reduced? or, do they have to use the "burn" function if there is one included in the contract in order to reduce supply?

0

Usually during creation of contract contract creater make two separate function for burning and transferring token. For sake of simplicity. Normally people will follow bellow syntax for transferring token in which you can not transfer to address(0) so your token wont burn.

function transfer(address recipient, uint256 amount) public {
        require(sender != address(0), "ERC20: transfer from the zero address");
    

And for burning amount people will use this syntax.

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

        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);
    }

In this function it will burn the amount from user account and reduce the total supply. It's up-to contract creater what he wants to write but Usually all programmer follow this approach. and it's way better then complex code. For reference read this code : link And sorry for my poor English. Enjoy your day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.