Owner Based Restriction in solidity

Authentication is very important in any project to control and give limited access to users for this purpose, in solidity we get this functionality with this pattern.

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract OwnerBasedRestriction{
    address owner;
        owner = msg.sender;    
    error unAuthorized();
    modifier onlyBy(address _addr){
        if(msg.sender != _addr)
            revert unAuthorized();
    function changeOwnerShip(address _newOwner)public onlyBy(owner){
        owner = _newOwner;
    function checkBalance()public view returns(uint){
        return address(this).balance;

By Shabair

Frontend | Blockchain | Smart Contract Developer