-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathEtherToken.sol
45 lines (40 loc) · 1.12 KB
/
EtherToken.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
35
36
37
38
39
40
41
42
43
44
45
pragma solidity ^0.4.0;
import "Tokens/StandardToken.sol";
/// @title Token contract - Token exchanging Ether 1:1.
/// @author Stefan George - <[email protected]>
contract EtherToken is StandardToken {
/*
* Constants
*/
// Token meta data
string constant public name = "Ether Token";
string constant public symbol = "ETH";
uint8 constant public decimals = 18;
/*
* Read and write functions
*/
/// @dev Buys tokens with Ether, exchanging them 1:1. Returns success.
function buyTokens()
external
payable
{
balances[msg.sender] += msg.value;
totalSupply += msg.value;
}
/// @dev Sells tokens in exchange for Ether, exchanging them 1:1. Returns success.
/// @param count Number of tokens to sell.
function sellTokens(uint count)
external
{
if (count > balances[msg.sender]) {
// Balance is too low
throw;
}
balances[msg.sender] -= count;
totalSupply -= count;
if (!msg.sender.send(count)) {
// Sending failed
throw;
}
}
}