-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathFreeBeer.sol
More file actions
44 lines (37 loc) · 1.58 KB
/
FreeBeer.sol
File metadata and controls
44 lines (37 loc) · 1.58 KB
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
35
36
37
38
39
40
41
42
43
44
pragma solidity ^0.4.16;
// FreeBeer
//
// This is a simple, HelloWorld style contract that allows anybody on the Ethereum
// network to send the contract owner some money. It illustrates:
//
// - Contract creation
// - Use of a payable method to transfer value
// - Event emission
contract FreeBeer {
// Each time money is transferred, emit the following Event to track who sender and value sent
event MoneySent(address sender, address recipient, uint256 amount);
// Declare the recipient of the contract
address recipient;
// The contract's constructor. This is called once (and only once) on contract creation. All it
// does is set the contract's recipient to the creator of the contract.
function FreeBeer() {
recipient = msg.sender;
}
// The contract's only usable method. It's marked with the payable keyword so it can accept
// value when called. Sends whatever value is included with the calling transaction to the
// owner of the contract (i.e., the recipient). If successful, emits a MoneySent event,
// and returns true. Returns false if transaction fails.
function gimmeMoney() payable returns (bool) {
if (recipient.send(msg.value)) {
MoneySent(msg.sender, recipient, msg.value);
return true;
}
return false;
}
// The contract's fallback function. This is a catch-all function that is executed whenever a
// contract is called and no public methods match, or no method was specified. In this case, just
// call .gimmeMoney() to send the contract owner whatever money is in the transaction.
function () payable {
gimmeMoney();
}
}