> 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.md).

# SharedWallet

* anyone can deposit.&#x20;
* owner can withdraw everything&#x20;
* assigned beneficiary can withdraw based on allowance variable

This is what we cooked up initially. We coded our own basic owner  functionality with the variable and require statements.

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

contract SharedWallet {
    address owner;
    uint balance
    address receiver;
    uint allowance;

    constructor(){
        owner = msg.sender;         //attribute owner on deployment
    }
    
    function deposit() payable public{
        balance += msg.value;
    }
    // OR :
    receive () external payable{
        balance += msg.value;
    }
    
    // centralising permissions:
    modifier onlyOwner(){
        require(msg.sender == owner, "you are not the owner");
        _;
    }
    
    function withdraw(uint _w_amt, address payable _to) public onlyOwner {
        require(_w_amt <= balance, "Not enough balance");
            balance -= _w_amt;
            _to.transfer(_w_amt);
    }
    
    function receiveAllowance(uint _w_amt, address payable _to) public {
        require(msg.sender == receiver, "must be beneficiary");
        require(_w_amt <= allowance, "Cannot exceed allowance or balance");
            balance -= _w_amt;
            _to.transfer(_w_amt);
    }
}
```

However, OpenZeppelin has already built a comprehensive ownership functionality, allowing for transfers, renouncement and much more. We can simply re-use it, by importing it.&#x20;

Our modifier onlyOwner should be removed as Ownable.sol also defines onlyOwner (line 42). This will cause an error, with Solidity expecting the `override` specifier.

&#x20;

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

// for Owner functionality - no need to built youself
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";

contract SharedWallet is Ownable{   //to extend base Ownable

    uint balance;
    address receiver;
    uint allowance;

    receive () external payable{    //receive eth
        balance += msg.value;
    }
    
    //check if you are the owner
    function isOwner() internal view returns(bool){
        return owner() == msg.sender;
    }

    function withdraw(uint _w_amt, address payable _to) public onlyOwner {
        require(_w_amt <= balance, "Not enough balance");
            balance -= _w_amt;
            _to.transfer(_w_amt);

    }

    function receiveAllowance(uint _w_amt, address payable _to) public {
        require(msg.sender == receiver, "must be beneficiary");
        require(_w_amt <= allowance, "Cannot exceed allowance or balance");
            balance -= _w_amt;
            _to.transfer(_w_amt);
    }
}
```

The latest OpenZeppelin contract does not have an isOwner() function anymore, so we have to create our own.&#x20;

Note that the owner() is a function from the Ownable.sol contract.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://calnix.gitbook.io/eth-dev/archive/brownie-projects/sharedwallet.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
