// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MintableERC20 is ERC20, Ownable {
uint8 private _decimals;
constructor(
string memory name,
string memory symbol,
uint256 initialSupply,
uint8 decimals_
) ERC20(name, symbol) Ownable(msg.sender) {
_decimals = decimals_;
_mint(msg.sender, initialSupply * 10 ** decimals_);
}
// Override decimals function to return custom decimals
function decimals() public view virtual override returns (uint8) {
return _decimals;
}
// Mint function - only owner can mint
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
// Burn function - anyone can burn their own tokens
function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
// Burn from allowance
function burnFrom(address account, uint256 amount) public {
_spendAllowance(account, msg.sender, amount);
_burn(account, amount);
}
}