Created
April 22, 2022 15:00
-
-
Save bartubozkurt/c4a00e91f43bad3e54928f791e41da58 to your computer and use it in GitHub Desktop.
View Function | Let's make our owner-variable private and instead add a simple getter function function
This file contains hidden or 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.3; | |
contract FunctionsExample { | |
mapping(address => uint) public balanceReceived; | |
address payable owner; | |
constructor() { | |
owner = payable(msg.sender); | |
} | |
function getOwner() public view returns(address) { | |
return owner; | |
} | |
function destroySmartContract() public { | |
require(msg.sender == owner, "You are not the owner"); | |
selfdestruct(owner); | |
} | |
function receiveMoney() public payable { | |
assert(balanceReceived[msg.sender] + msg.value >= balanceReceived[msg.sender]); | |
balanceReceived[msg.sender] += msg.value; | |
} | |
function withdrawMoney(address payable _to, uint _amount) public { | |
require(_amount <= balanceReceived[msg.sender], "not enough funds."); | |
assert(balanceReceived[msg.sender] >= balanceReceived[msg.sender] - _amount); | |
balanceReceived[msg.sender] -= _amount; | |
_to.transfer(_amount); | |
} | |
receive() external payable { | |
receiveMoney(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment