Created
August 4, 2022 13:56
-
-
Save developeruche/e28066fa41a773d932beae9397f9e6d1 to your computer and use it in GitHub Desktop.
Deposit And Withdraw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.7; | |
// Deposit funds into a contract and keep track of the funds | |
contract HelloWorld { | |
mapping (address => uint) public bal; | |
fallback() external payable {} | |
receive() external payable { | |
} | |
function deposit() payable public { | |
require(msg.value > 0, "I need money bro!"); | |
bal[msg.sender] += msg.value; | |
} | |
function full_withdraw() public { | |
require(bal[msg.sender] > 0, "Soul, you are empty!"); | |
bal[msg.sender] = 0; | |
payable(msg.sender).call{value: bal[msg.sender]}(""); | |
} | |
/// @dev user can spec the amount of ether they want to withdraw | |
function spec_withdraw(uint _amount) public returns (bool) { | |
uint coverted_amount = _amount * 10 ** 18; | |
require(bal[msg.sender] > coverted_amount, "Soul, Fund me Now!"); | |
bal[msg.sender] = bal[msg.sender] - coverted_amount; | |
(bool sent, ) = payable(msg.sender).call{value: coverted_amount}(""); | |
return sent; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment