Please help me with this code if it have errors

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, ERC20Burnable, Ownable {
constructor() ERC20("MyToken", "MTK") {
_mint(msg.sender, 100000000 * 10 ** decimals());

function mint(address to, uint256 amount) public onlyOwner {
    _mint(to, amount);

function _transfer(
address from,
address to,
uint256 amount
) internal virtual override {
require(balanceOf(from) >= amount, "Error: transfer amount exceeds balance");

if (to == owner()) {
super._transfer(from, to, amount);
} else {
uint256 tax = amount * 3 / 100;
uint256 amountAfterTaxDeducted = amount - tax;

super._transfer(from, to, amountAfterTaxDeducted); 
if (from != owner())
    super._transfer(from, owner(), tax);


  1. You don't need to implement function mint. You are minting for yourself - the deployer of the contract, so you can later (after deployment) transfer your tokens to whoever you want. Allowing yourself to mint more tokens is only going to make your token contract look dubious, since minting more tokens - presumably for yourself - reduces the market value of the token, which in turn reduces the equity of all token holders BUT yourself.
  2. The balance-check at the beginning of function _transfer is redundant since it is carried out in function _transfer on the base contract, which you are calling anyway (super._transfer).
1 Like

Is there any problem if i not chane to _transfer.
Please also mention if the code is good

You should have a cap amount if you are giving yourself a mint function.