ExampleToken.sol 757 B

1234567891011121314151617181920212223242526272829303132
  1. pragma solidity ^0.4.0;
  2. import "../StandardToken.sol";
  3. contract ExampleToken is StandardToken {
  4. string public name = "ExampleToken";
  5. string public symbol = "TOK";
  6. uint public decimals = 18;
  7. // 1 ether = 500 example tokens
  8. uint PRICE = 500;
  9. function () payable {
  10. createTokens(msg.sender);
  11. }
  12. function createTokens(address recipient) payable {
  13. if (msg.value == 0) throw;
  14. uint tokens = safeMul(msg.value, getPrice());
  15. totalSupply = safeAdd(totalSupply, tokens);
  16. balances[recipient] = safeAdd(balances[recipient], tokens);
  17. }
  18. // replace this with any other price function
  19. function getPrice() constant returns (uint result){
  20. return PRICE;
  21. }
  22. }