3

So, I recently created a standard ERC20 token but I need to implement "mint" and "owner" functionality. I see that in older implementations but openzeppelin no longer has contracts like "Mintable" and "Ownable". How do I implement this "mint" functionality? I do see it in ERC20.sol but not able to test it in console(truffle).

1 Answer 1

5

They are still internal functions of the ERC-20 contract, see docs. So you can simply create a new contract that inherits from that one and add the mint function:

pragma solidity ^0.6.10;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MintableToken is Ownable, ERC20 {
    constructor() public ERC20("Gold", "GLD") { }

    function mint(address account, uint256 amount) public onlyOwner {
        _mint(account, amount);
    }

    function burn(address account, uint256 amount) public onlyOwner {
        _burn(account, amount);
    }
}
2
  • how did you set owner of the contract?
    – alper
    Commented Jun 21, 2023 at 12:35
  • 1
    In the current version of Ownable you could e.g. do constructor(address originalOwner) Ownable(originalOwner) ERC20("Gold", "GLD") {}. Commented Jun 22, 2023 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.