构造函数充可以在合约部署时对变量进行初始化
contract A {
string public text;
constructor(string memory _text) {
text = _text;
}
}
常用于指定合约的所有者地址用
contract B {
string public owner;
constructor(string memory _owner) {
owner = _owner;
}
modifier onlyOnwer() {
require(owner == msg.sender, "is not owner");
_;
}
function test() public view returns (uint){
return 1;
}
}