Skip to content

Instantly share code, notes, and snippets.

@glaksmono
Created August 22, 2021 08:13
Show Gist options
  • Save glaksmono/7274deb78e8abdc6b947992cb0ca2758 to your computer and use it in GitHub Desktop.
Save glaksmono/7274deb78e8abdc6b947992cb0ca2758 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.13+commit.5b0b510c.js&optimize=false&runs=200&gist=
pragma solidity ^0.5.13;
contract FunctionExample {
mapping(address => uint) public balanceReceived;
address payable owner;
constructor() public {
owner = msg.sender;
}
function getOwner() public view returns(address) {
return owner;
}
function convertWeiToInt(uint _amountInWei) public pure returns(uint) {
return _amountInWei / 1 ether;
}
function destroySmartContract() public {
require(msg.sender == owner, "You are not the owner of the contract");
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 fund");
assert(balanceReceived[msg.sender] >= balanceReceived[msg.sender] - _amount);
balanceReceived[msg.sender] -= _amount;
_to.transfer(_amount);
}
function () external payable {
receiveMoney();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment