Skip to content

Instantly share code, notes, and snippets.

@manabubannai
Created Mar 29, 2022
Embed
What would you like to do?
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract donation {
address public owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
struct Contributors {
uint id;
string name;
uint256 amount;
address sender_address;
}
uint256 id = 0;
mapping(uint => Contributors) public contributor;
function doDonation(string memory name) public payable {
id += 1;
contributor[id] = Contributors(id, name, msg.value, msg.sender);
}
function getBalance() public view returns(uint) {
return address(this).balance;
}
function withdrawMoney(address payable _to) public onlyOwner {
_to.transfer(getBalance());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment