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
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);
}
}
-
-
1In 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