-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuyMeCoffee.sol
34 lines (27 loc) · 879 Bytes
/
BuyMeCoffee.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Coffee {
// data structure to store the details
struct Memo {
string name;
string message;
uint256 timestamp;
address from;
}
// defining a struct type of array
Memo[] public memos; // Made public to allow easy access
address payable public owner;
constructor() {
owner = payable(msg.sender);
}
function buyCoffee(string memory name, string memory message) public payable {
require(msg.value > 0, "Please pay greater than 0 ether");
owner.transfer(msg.value);
// dynamic array so we are using push
memos.push(Memo(name, message, block.timestamp, msg.sender));
}
// getter function for memos
function getMemos() public view returns(Memo[] memory) {
return memos;
}
}