What is DeFi? A new technology that replaces banks and financial corporations with smart contracts.
// SPDX-License-Identifier: UNLICENSEDpragmasolidity ^0.8.0;// Uncomment this line to use console.log// import "hardhat/console.sol";contract BuyMeACoffee {// Event to emit when a Memo is createdeventNewMemo(addressindexed from,uint256 timestamp,string name,string message );// Memo struct.structMemo {address from;uint256 timestamp;string name;string message; }// List of all memos received from friends. Memo[] memos;// Address of contract deployer.addresspayable owner;// Deploy logic.constructor() { owner =payable(msg.sender); }/** * @dev buy a coffee for contract owner * @param _name name of the coffee buyer * @param _message a nice message from the coffee buyer */functionbuyCoffee(stringmemory_name,stringmemory_message)publicpayable {require(msg.value >0,"can't buy coffee with 0 eth");// Add the memo to storage. memos.push(Memo(msg.sender, block.timestamp, _name, _message));// Emit a log event when a new memo is created.emitNewMemo(msg.sender, block.timestamp, _name, _message); }/** * @dev send the entire balance stored in this contract to the owner */functionwithdrawTips() public {require(owner.send(address(this).balance)); }/** * @dev retrieve all the memos received and stored on the blockchain */functiongetMemos() publicviewreturns (Memo[] memory) {return memos; }}