Last active
April 11, 2023 08:39
-
-
Save Chmarusso/d8d5349084b57c6f02c32ea30dbed79c to your computer and use it in GitHub Desktop.
Simple smart contract
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
pragma solidity ^0.8.7; | |
// SPDX-License-Identifier: MIT | |
contract FeeCollector { // | |
address public owner; | |
uint256 public balance; | |
constructor() { | |
owner = msg.sender; // store information who deployed contract | |
} | |
receive() payable external { | |
balance += msg.value; // keep track of balance (in WEI) | |
} | |
function withdraw(uint amount, address payable destAddr) public { | |
require(msg.sender == owner, "Only owner can withdraw"); | |
require(amount <= balance, "Insufficient funds"); | |
destAddr.transfer(amount); // send funds to given address | |
balance -= amount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, very informative.