0

I have an existing ERC20 token / contract that I would like to be able to provide rewards that could be minted to the supply. The existing contract already has a _mint() function, but it's labeled as 'internal virtual.' It isn't private, and its part of the ERC20 declared construct, so I assume it's accessible.

How do I either: Extend the contract to access this _mint() function for rewards, or create a new contract that can perform the functions of this one with its approval?

Current contract code looks like this:

contract ERC20 is Context, IERC20, IERC20Metadata {
...
...
     function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }
}

1 Answer 1

0

Assuming your current contract is not deployed yet, you can create a new contract that inherits from your current contract and exposes a function externally (external or public) that calls super._mint(...).

Have a look at the following snippet:

contract SomeContract is ERC20 {
...

    function mint(address account, uint256 amount) external override {
        ...
        super._mint(account, amount);
        ...
    }

...
}

If your current contract is already deployed, you are not able to invoke the _mint(...) function.

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.