文章目录 写一个合约 1. 使用代理部署 并添加拥有者 2. 没有name number为10 3. 使用代理升级部署 填写上面代理的合约地址 4. 合约地址没有变,但是添加了name,并且保存了number的属性值
写一个合约
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; 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 _authorizeUpgrade ( address newImplementation) internalonlyOwneroverride{ }
}
1. 使用代理部署 并添加拥有者
2. 没有name number为10
3. 使用代理升级部署 填写上面代理的合约地址
4. 合约地址没有变,但是添加了name,并且保存了number的属性值