Common smart contract patterns
In this section, we will discuss some common design and programming patterns for the smart contract programming language.
Access restriction
Access restriction is a solidity security pattern. It only allows authorized parties to access certain functions. Due to the public nature of the blockchain, all data on the blockchain is visible to anyone. It is critical to declare your contract function, state with restricted access control, and provide security against unauthorized access to smart contract functionality.
pragma solidity ^0.4.24; contract Ownable { address owner; uint public initTime = now; constructor() public { owner = msg.sender; } //check if the caller is the owner of the contract modifier onlyOwner { require(msg.sender == owner,"Only Owner Allowed." ); _; } //change the owner of the contract //@param _newOwner the address of the new owner of the contract. function changeOwner(address _newOwner) public onlyOwner { owner = _newOwner; ...