How to use ERC20PresetMinterPauserUpgradeable preset

I’m relatively new to how to write upgradeable contracts.
I want to use the ERC20PresetMinterPauserUpgradeable.sol preset for my contract but I’m confused about how to implement it.

I saw this example on how to create an upgradeable ERC20 and the example on how to use this same preset by copying the code into your own contract but I’m not sure how this translates to using the preset as an inheritable contract.

Here’s what I assumed to make my contract as:

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.2 <0.8.1;

import "@openzeppelin/contracts-upgradeable/proxy/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/presets/ERC20PresetMinterPauserUpgradeable.sol";

contract MyToken is Initializable, ERC20PresetMinterPauserUpgradeable {
    function initialize(
        string memory name,
        string memory symbol,
        uint256 initialSupply
    ) public virtual initializer {
        __ERC20PresetMinterPauserUpgradeable__init(name, symbol);
    }

    function _beforeTokenTransfer(
        address from, 
        address to, 
        uint256 amount
    ) internal virtual override(ERC20PresetMinterPauserUpgradeable) {
        super._beforeTokenTransfer(from, to, amount);

        /
    }
}

Does this still work?

I think the function name should be __ERC20PresetMinterPauser_init, and I think you should call ERC20PresetMinterPauserUpgradeable.initialize() to initialize contract rather than __ERC20PresetMinterPauser_init(), but just calling __ERC20PresetMinterPauser_init is fine.

2 Likes

Thanks! I will try that.

1 Like

Hi @platocrat,

Welcome to the community :wave:

Were you able to get it working?