I am deploying a proxy on an ERC721 and Ownable contract. The problem is that the constructor of Ownable is not called on the initialize function so the owner is not defined and the onlyOwner modifier is therefore not working appropriately. Any solution to this issue?
The beginning of the contract is the following:
contract Collection is ERC721URIStorage, Initializable, Ownable {
string private __name;
string private __symbol;
string public collectionURI;
uint256 public totalSupply;
uint256 public maxTotalSupply;
uint256 mintFee;
constructor(
string memory _name,
string memory _token,
uint256 _maxTotalSupply,
string memory _collectionURI,
uint256 _mintFee
) ERC721(_name, _token) {
__name = _name;
__symbol = _token;
collectionURI = _collectionURI;
maxTotalSupply = _maxTotalSupply;
mintFee = _mintFee;
}
function initialize(
string memory _name,
string memory _token,
uint256 _maxTotalSupply,
string memory _collectionURI,
uint256 _mintFee
) public initializer {
__name = _name;
__symbol = _token;
collectionURI = _collectionURI;
maxTotalSupply = _maxTotalSupply;
mintFee = _mintFee;
}
The variables __name and __symbol are the workaround I created so that it is not needed to call the ERC721 constructor. The problem is the Ownable contract that has the following line:
_transferOwnership(_msgSender());
Actually adding that line to the end of the initialize function on the contract works perfectly. I am wondering if there is a more elegant solution than those workarounds.