Getting contract is not upgrade safe

Using Oppenzeppelin version 3.3.0 and hardhat version v2.02

Hello,

I’m trying to upgrade my contract using hardhat

My contract uses

 import "@openzeppelin/contracts/math/SafeMath.sol";

 import "@openzeppelin/contracts/proxy/Initializable.sol";

 import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

 import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

 import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

contract EPNSCore is Initializable, ReentrancyGuard {
    using SafeMath for uint256;

    /* ***************
     * CONSTRUCTORS, MODIFIERS AND FUNCTIONS
     *************** */
    function initialize( ) public initializer {

when I run npx hardhat run --network ropsten scripts/deploy.js

I get

1 Like

As the error indicates, your contract is extending from ReentracyGuard which is not upgradeable, therefore EPNSCore is not upgradeable either. You need to use contracts-upgradeable, the upgrade-safe version of OpenZeppelin Contracts.

So you’ll need to install the package and change your imports (all of them) like this:

 import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
1 Like

That worked! Thanks :slight_smile:

2 Likes