I have very little experience with solidity.
I need to create an ERC20 token that will be as simple as possible, with the following properties:
Does this code look good? It works great for me on my private testnet, I'm just wondering if there are any obvious bugs/issues you guys can see? Thanks in advance! Planning to deploy it on Ethereum mainnet using the Remix online IDE.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract Token is ERC20, ERC20Burnable, Ownable {
constructor() ERC20("MyToken", "MYTOK") {
_mint(msg.sender, 1000 * (10 ** uint256(decimals())));
}
function decimals() public pure override returns (uint8) {
return 6;
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
I must be able to burn some whenever I want
The imported OpenZeppelin ERC20Burnable@v4.9.2 (current version) enables you to burn your own tokens, and to burn someone else's tokens if they gave you prior approval.
Your current implementation doesn't enable the owner
to burn others' tokens without their prior approval.
I must be able to mint some whenever I want
The current implementation of your mint()
public function enables the owner
address to mint new tokens without limitations on how often or how many tokens can be minted.
Having said that, there's a technical limit of 2^256 - 1 max supply including decimals, which is roughly "1 and 70 zeros of tokens" if you account for the decimals.
It must not have bugs such as backdoors / reentrance issues / race conditions, etc.
Generally, OpenZeppelin libraries are very well tested, secure, and should not contain obvious bugs.
There doesn't seem to be any known issue in your implementation that builds on top of the OZ code.