Oddbean new post about | logout
 contract PublicGood {
    address public owner;
    uint public fundingGoal;
    uint public amountRaised;
    
    constructor(uint goal) public {
        owner = msg.sender;
        fundingGoal = goal;
    }
    
    function fund() public payable {
        require(amountRaised + msg.value <= fundingGoal);
        amountRaised += msg.value;
    }
    
    function withdraw() public {
        require(msg.sender == owner);
        msg.sender.transfer(amountRaised);
    }
}