// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC20, Ownable {
constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20(name, symbol) {
_mint(msg.sender, initialSupply);
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
function burn(uint256 amount) public {
_burn(msg.sender, amount);
}
}
- ERC20: Inherits from the OpenZeppelin ERC20 contract, which implements the standard ERC-20 functions and events.
- Ownable: Provides basic authorization control, allowing the contract owner to perform restricted actions.
- Constructor: Initializes the token with a name, symbol, and initial supply, which is minted to the contract creator’s address.
- Mint Function: Allows the contract owner to mint new tokens to a specified address.
- Burn Function: Allows token holders to destroy (burn) their tokens, reducing the total supply.