CrowdsaleToken.sol 807 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. pragma solidity ^0.4.8;
  2. import "./StandardToken.sol";
  3. /*
  4. * CrowdsaleToken
  5. *
  6. * Simple ERC20 Token example, with crowdsale token creation
  7. */
  8. contract CrowdsaleToken is StandardToken {
  9. string public name = "CrowdsaleToken";
  10. string public symbol = "CRW";
  11. uint public decimals = 18;
  12. // 1 ether = 500 example tokens
  13. uint PRICE = 500;
  14. function () payable {
  15. createTokens(msg.sender);
  16. }
  17. function createTokens(address recipient) payable {
  18. if (msg.value == 0) {
  19. throw;
  20. }
  21. uint tokens = safeMul(msg.value, getPrice());
  22. totalSupply = safeAdd(totalSupply, tokens);
  23. balances[recipient] = safeAdd(balances[recipient], tokens);
  24. }
  25. // replace this with any other price function
  26. function getPrice() constant returns (uint result) {
  27. return PRICE;
  28. }
  29. }