Skip to content

Instantly share code, notes, and snippets.

@Chmarusso
Last active April 11, 2023 08:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Chmarusso/d8d5349084b57c6f02c32ea30dbed79c to your computer and use it in GitHub Desktop.
Save Chmarusso/d8d5349084b57c6f02c32ea30dbed79c to your computer and use it in GitHub Desktop.
Simple smart contract
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;
}
}
@SanaCheema123
Copy link

Thanks, very informative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment