> For the complete documentation index, see [llms.txt](https://calnix.gitbook.io/eth-dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calnix.gitbook.io/eth-dev/archive/brownie-projects/sharedwallet/common-code-contract.md).

# Common Code Contract

We will split the allowance checks into a seperate contract, like so:

```solidity
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.1;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

contract Allowance is Ownable{

    mapping (address=> uint) allowance;
    
        //check if you are the owner
    function isOwner() internal view returns(bool){
        return owner() == msg.sender;
    }
    modifier ownerOrBeneficiary(uint _amt) {
        require(isOwner() || _amt <= allowance[msg.sender], "you are not allowed");
        _;
    }

    function reduceAllowance(uint _amt, address _who) internal {
        allowance[_who] -= _amt;
    }
}

contract SharedWallet is Allowance{

    receive () external payable{    //receive eth
        allowance[msg.sender] += msg.value;
    }

    function withdraw(uint _amt, address payable _to) public ownerOrBeneficiary(_amt) {
        require(_amt <= address(this).balance, "There are not enough funds");
        if(isOwner() == false){
            reduceAllowance(_amt,msg.sender);
        }
        _to.transfer(_amt);

    }
}
```

Allowance inherits from Ownable, and Shared Wallet inherits from Allowance (+ Ownable indirectly).

When deploying, you would deploy the SharedWallet contract.

![](https://1628544884-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTgomzlmn9NrxUY0OQ3cD%2Fuploads%2Fryr01oTekIaS4EwzR6Mj%2Fimage.png?alt=media\&token=4ba4bbf6-93e6-4a80-b338-77150820299d)
