BuyMeaCoffee
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
contract BuyMeacoffe {
    uint public numberOfCoffees;
    uint public balance;
    address payable public owner;
    
    event BuyCoffee(
        address indexed sender,
        string message,
        uint amount,
        uint timestamp
    );
    constructor() payable {
        owner = payable(msg.sender);
    }
    struct Coffee {
        address sender;
        string message;
        uint timestamp;
        
    }
    Coffee [] coffee;
    function getCoffee() external view returns (Coffee [] memory) {
        return coffee;
    }
    function getTotalCoffee() external view returns(uint){ 
        return numberOfCoffees;
    }
    function getBalance()external view returns (uint) {
        return balance;
    }
    function buyCoffee(string memory _message) external payable {
        
        uint minimumCost = 0.001 ether;
        uint _timestamp = block.timestamp;
        uint _amount = msg.value;
        require(bytes(_message).length !=0,"The message cannot be empty");
        require(msg.value>=minimumCost, "You must send at least 0.001 ether");
        numberOfCoffees += 1;
        balance+=_amount;
        coffee.push(Coffee(msg.sender,_message,_timestamp));
 
        (bool sent,) = owner.call{value: _amount}("");
        require(sent, "Failure to send coffee");
        emit BuyCoffee(msg.sender,_message,_amount,_timestamp);
    }
  
}Last updated
