写一个合约
// SPDX-License-Identifier: MIT // Compatible with OpenZeppelin Contracts ^5.0.0 pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol"; contract MyContract is Initializable, PausableUpgradeable, OwnableUpgradeable, UUPSUpgradeable { using CountersUpgradeable for CountersUpgradeable.Counter; CountersUpgradeable.Counter private changeId; uint public number; // string public name; /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } function initialize(address initialOwner) initializer public { __Pausable_init(); __Ownable_init(initialOwner); __UUPSUpgradeable_init(); } function pause() public onlyOwner { _pause(); } function unpause() public onlyOwner { _unpause(); } function updateNumber(uint _number) public returns (uint, uint) { number = _number; changeId.increment(); uint id = changeId.current(); return (number, id); } // function addName(string memory _name) public returns (string memory){ // name = _name; // return name; // } function _authorizeUpgrade(address newImplementation) internal onlyOwner override {} }
1. 使用代理部署 并添加拥有者
2. 没有name number为10
3. 使用代理升级部署 填写上面代理的合约地址
4. 合约地址没有变,但是添加了name,并且保存了number的属性值