Request: Example of a Mintable and Pausable ERC20 token

Hey Everyone!

I am currently learning to develop ERC20 Tokens.
I was wondering if there is an example of a Mintable and Pausable ERC20 Token Contract.

2 Likes

Hi @niru.kun14,

Welcome to the community :wave:. Thanks for posting here.

I have created an example of an ERC20 token inheriting from ERC20Mintable and ERC20Pausable extensions, with pause also pausing the mint function.

The following code hasn’t been tested, and if you use this code, it should be appropriately tested and audited.

MyToken.sol

pragma solidity ^0.5.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Mintable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol";

contract MyToken is ERC20, ERC20Detailed, ERC20Mintable, ERC20Pausable {
    constructor() ERC20Detailed("MyToken", "TKN", 18) public {
    }

    function mint(address account, uint256 amount) public whenNotPaused returns (bool) {
        return super.mint(account, amount);
    }
}
3 Likes

Thank you very much @abcoathup. I will now proceed to the testing of this example.

1 Like

Hi @niru.kun14,

Feel free to ask all the questions that you need.

I ran a couple of manual checks using Remix but it needs thorough testing.

1 Like

Hi, I have been thinking about using this approach for my current project. Only one issue, these “ERC20Mintable”, “ERC20Detailed”, and “ERC20Pausable” modules aren’t available in OpenZeppelin Contracts v3.x. But, I can do that by using v2.x. Is it okay to use v2.x in July 2020?

1 Like

Hi @PradhumnaPancholi,

Whilst you can still use OpenZeppelin Contracts 2.x, I would suggest using OpenZeppelin Contracts 3.x.

You can use the preset ERC20 contract as is or you can create your own inheriting from either the preset or from ERC20. As per my other reply: How to create a mintable ERC20 token?

1 Like

Thanks, I did it some other way for gig I was doing when I asked the question. But, now I think I have better understating of OpenZeppelin’s ERC20 modules and pressets. And I would do to in my upcoming gigs.

1 Like

Creating pausable ERC20 token using openzeppelin version 4 and solc 0.8.9

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

/*
*Author: Olaboye David Tobi
*Email: dtobi59@gmail.com
*Github: @dtobi59
*Twitter: @devtobi59
*/

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";

//Note: Token is Mintable due to the ERC20Capped Inheritence
contract DaveMeToken is ERC20Capped, ERC20Pausable {

  using SafeMath for uint256;

  uint256 constant MAXIMUMSUPPLY = 5000000000000000000000000; //5million uint 

  constructor() ERC20("DaveMe", "PMe") ERC20Capped(MAXIMUMSUPPLY) {
      _mint(msg.sender, MAXIMUMSUPPLY);
  }


  function _mint(address account, uint256 amount) override(ERC20, ERC20Capped) internal  {
    super._mint(account, amount);
  }

  function _beforeTokenTransfer(address from, address to, uint256 amount) override(ERC20, ERC20Pausable) internal {
    super._beforeTokenTransfer(from, to, amount);
  }



}