23-02-28First Post: 2023-02-28Last Update: 2023-03-012023-02-28锁与Modifier12345678910111213141516171819202122232425262728293031323334353637pragma solidity ^0.8.17;//SPDX-License-Identifier: MITcontract lock_ { address owner; constructor() { owner = msg.sender; } modifier onlyOwner() { require(owner == msg.sender, "not owner! "); _; } modifier validAddress(address addr) { require(addr != address(0), "not valid address!"); _; } function changeOwner(address newOwner) public onlyOwner validAddress(newOwner) { owner = newOwner; //更改账户拥有者需要确认是否为袁拥有者跟新地址有效性 } bool lock; modifier noReentrancy { require(!lock, "No reentrancy!");//函数被调用的时候拒绝访问 lock = true; _; lock = false; } uint x = 10; function decrease(uint i) public noReentrancy { x-=i; if(i>1) { decrease(i-1); } }} 事件123456789101112pragma solidity ^0.8.17;//SPDX-License-Identifier:MITcontract eventTest { event log(address indexed caller, string message); event anotherLog(); function test() public { emit log(address(0), "hello1"); emit log(msg.sender, "hello2"); emit anotherLog(); } } 继承相关的构造器12345678910111213141516171819202122232425262728293031pragma solidity ^0.8.17;//SPDX-License-Identifier:MITcontract A{ uint x; constructor(uint _x) { x = _x; }}contract B{ uint y; constructor(uint _y) { y = _y; }}contract C is B(1), A(2) {}contract D is B, A { constructor(uint _x, uint _y) A(_x) B(_y) { }}contract E is A, B { constructor(uint _x, uint _y) B(_y) A(_x) { }}contract F is A, B { constructor() A(1) B(2) { }}∧≡