npm install -g @openzeppelin/cli
oz --version
mkdir hello-oz
cd hello-oz
npm init -y
oz init
npm install @openzeppelin/upgrades --save
部署
在contracts文件夹中创建HelloOz.sol文件
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.0;
import "@openzeppelin/upgrades/contracts/Initializable.sol";
contract HelloOz is Initializable {
string public name;
uint256 public dec;
uint256 public inc;
function initialize(string memory _name) initializer public {
name = _name;
}
function decrement(uint256 x) public returns (uint256) {
return dec = x - 1;
}
function increment(uint256 x) public returns (uint256) {
return inc = x + 1;
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.0;
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
contract HelloOz is Initializable {
string public name;
uint256 public dec;
uint256 public inc;
using SafeMath for uint256;
function initialize(string memory _name) initializer public {
name = _name;
}
function decrement(uint256 x) public returns (uint256) {
return dec = x.sub(1);
}
function increment(uint256 x) public returns (uint256) {
return dec = x.add(1);
}
}