-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample30.sol
More file actions
34 lines (20 loc) · 824 Bytes
/
example30.sol
File metadata and controls
34 lines (20 loc) · 824 Bytes
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
pragma solidity 0.4.21;
contract RichToken{
mapping(address => uint) public contributor_to_ethAmount_map;
address[] public contributors;
//contribute eth
function contribute() public payable returns (uint) {
require(msg.value > 0 && msg.value <= 10 ether, "you only can contribute up to 10 eth at a time!");
contributor_to_ethAmount_map[msg.sender] = msg.value + contributor_to_ethAmount_map[msg.sender];
return msg.value;
}
//withdraw your eth
function withdrawAll() public payable returns (uint) {
uint amount = contributor_to_ethAmount_map[msg.sender];
msg.sender.call.value(amount)("");
contributor_to_ethAmount_map[msg.sender] = 0;
}
//fall back
function () payable external {
}
}