OZ ERC20 initialOwner error

Using simple OZ ERC20:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

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

contract MyToken is ERC20, Ownable {
    constructor(address initialOwner)
        ERC20("MyToken", "MTK")
        Ownable(initialOwner)
    {}

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

When Ownable(initialOwner) is set to initialOwner there is an error: TypeError: Wrong argument count for modifier invocation: 1 arguments given but expected 0.

After removing initialOwner from Ownable, so it's Ownable(), everything works. Is it ok ?

I would like to add that this only happens on remix. In the hardhat project it works just fine. Any ideas ?

This is because of the workspace being an old one. It imports the old version of OZ library.

Rn I can think of only one way(I'll update if I get any other) which is creating a new workspace.

You can create a new workspace here:

image

And the new work space will import new OZ files.

1 Like

Works like a charm. I added the new oz contracts to the old workspace and here was the problem..

Thank you

1 Like