SharedWallet
https://ethereum-blockchain-developer.com/040-shared-wallet-project/03-open-zeppelin/
//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);
}
}Last updated