ERC20 metadata and ERC20Detailed

You can install the latest release with

npm install @openzeppelin/contracts@solc-0.7

This will install OpenZeppelin Contracts 3.4.1 for Solidity 0.7

It really depends on your use case. Can you mint all of the tokens initially and then lock them, or do you need to mint at the predefined stages.

ERC20Capped does this by checking the cap before minting.

You can do this with Access Control, either Ownable or Roles: https://docs.openzeppelin.com/contracts/3.x/access-control

Using ERC20PresetMinterPauser the deployer is given the minter and pauser roles.

You also need to appropriately secure these admin accounts:

It is available if you extend from ERC20Burnable or add functionality to call _burn

I recommend multifile verification rather than flattening: How to verify with Hardhat or Truffle a smart contract using OpenZeppelin Contracts

I would use flattening as a last resort.


:warning: I am a Community Manager and not a Security Researcher.
Any contracts with value should be appropriately tested and audited.


You only need to extend from ERC20PresetMinterPauser and ERC20Capped
For custom (non-18 decimals) you can use _setupDecimals

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

import "@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";

contract MyToken is ERC20PresetMinterPauser, ERC20Capped {
    constructor (uint256 cap) ERC20PresetMinterPauser("MyToken", "TKN") ERC20Capped(cap) {
        _setupDecimals(9);
        _mint(msg.sender, 9000 * (10 ** uint256(decimals())));
    }
    
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20PresetMinterPauser, ERC20Capped) {
        super._beforeTokenTransfer(from, to, amount);
    }
}

As an aside, you can Format code in the forum.