# Please help me with this code if it have errors

**URL:** <https://forum.openzeppelin.com/t/please-help-me-with-this-code-if-it-have-errors/36483>\
**Category:** Developer Wanted\
**Created:** [May 30, 2023, 2:35am UTC](https://forum.openzeppelin.com/t/please-help-me-with-this-code-if-it-have-errors/36483 "2023-05-30T02:35:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nebuhan\_N](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/nebuhan_n/32/18644_2.png) [@Nebuhan\_N](https://forum.openzeppelin.com/u/Nebuhan_N)\
**Post date:** [May 30, 2023, 2:35am UTC](https://forum.openzeppelin.com/t/please-help-me-with-this-code-if-it-have-errors/36483/1 "2023-05-30T02:35:32Z")

</div>

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

```

}

---

<div class="post-metadata">

**Author:** ![barakman](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/barakman/32/855_2.png) [@barakman](https://forum.openzeppelin.com/u/barakman)\
**Post date:** [May 30, 2023, 2:53am UTC](https://forum.openzeppelin.com/t/please-help-me-with-this-code-if-it-have-errors/36483/2 "2023-05-30T02:53:09Z")

</div>

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`).

---

<div class="post-metadata">

**Author:** ![Nebuhan\_N](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/nebuhan_n/32/18644_2.png) [@Nebuhan\_N](https://forum.openzeppelin.com/u/Nebuhan_N)\
**Post date:** [May 30, 2023, 4:01am UTC](https://forum.openzeppelin.com/t/please-help-me-with-this-code-if-it-have-errors/36483/3 "2023-05-30T04:01:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KevinPeregud](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/kevinperegud/32/17314_2.png) [@KevinPeregud](https://forum.openzeppelin.com/u/KevinPeregud)\
**Post date:** [May 31, 2023, 5:08am UTC](https://forum.openzeppelin.com/t/please-help-me-with-this-code-if-it-have-errors/36483/4 "2023-05-31T05:08:35Z")

</div>

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