How to use Ownable together Initializable in upgradeable contract

hi all,
I've tried with upgrade contract by follow this

I also searched and read this post Using Ownable + Upgradeable - Archive / SDK - OpenZeppelin Forum

But at my computer it not works, It seems due to different version. My current versions is

"@openzeppelin/hardhat-upgrades": "^3.1.1",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2",

In my version i do not see OwnableUpgradeSafe . I tried with these

import  "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import  "@openzeppelin/contracts/proxy/utils/Initializable.sol";

Those have both modifiers that I need is initializer and onlyOwner but I can't import both of them because error

Identifier already declared.

This seems caused by OwnableUpgradeable has this import

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

How can I resolve it? thank you

The imports for both should be from @openzeppelin/contracts-upgradeable

For some examples, go to and enable Ownable and Upgradeability.

1 Like