Install the upgradeable contracts package from OpenZeppelin:
npm install @openzeppelin/contracts-upgradeable
When writing an upgradeable contract, replace constructors with initializer functions.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
contract MyUpgradeableNFT is Initializable, ERC721Upgradeable, OwnableUpgradeable {
function initialize(address owner) initializer public {
__ERC721_init("MyUpgradeableNFT", "NFT");
__Ownable_init(owner);
}
}
upgrading smart contracts
npm install @openzeppelin/contracts-upgradeable @openzeppelin/contracts
OwnableUpgradeable.sol
AccessControlUpgradeable.sol