Smart Money Implementation¶
Are you up for a small challenge?
Write a smart contract that allows for:
- Deposits from everyone
- Withdrawals only in the amount that was deposited by the person who likes to withdraw
In this video I'm going to show you a sample solution
Sample Solution¶
And this is my sample solution to the challenge:
//SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
contract SendWithdrawMoney {
uint public balanceReceived;
function deposit() public payable {
balanceReceived += msg.value;
}
function getContractBalance() public view returns(uint) {
return address(this).balance;
}
function withdrawAll() public {
address payable to = payable(msg.sender);
to.transfer(getContractBalance());
}
function withdrawToAddress(address payable to) public {
to.transfer(getContractBalance());
}
}