EIP20.sol 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Implements EIP20 token standard: https://github.com/ethereum/EIPs/issues/20
  3. .*/
  4. pragma solidity ^0.4.18;
  5. import "./EIP20Interface.sol";
  6. contract EIP20 is EIP20Interface {
  7. uint256 constant private MAX_UINT256 = 2**256 - 1;
  8. mapping (address => uint256) public balances;
  9. mapping (address => mapping (address => uint256)) public allowed;
  10. /*
  11. NOTE:
  12. The following variables are OPTIONAL vanities. One does not have to include them.
  13. They allow one to customise the token contract & in no way influences the core functionality.
  14. Some wallets/interfaces might not even bother to look at this information.
  15. */
  16. string public name; //fancy name: eg Simon Bucks
  17. uint8 public decimals; //How many decimals to show.
  18. string public symbol; //An identifier: eg SBX
  19. function EIP20(
  20. uint256 _initialAmount,
  21. string _tokenName,
  22. uint8 _decimalUnits,
  23. string _tokenSymbol
  24. ) public {
  25. balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
  26. totalSupply = _initialAmount; // Update total supply
  27. name = _tokenName; // Set the name for display purposes
  28. decimals = _decimalUnits; // Amount of decimals for display purposes
  29. symbol = _tokenSymbol; // Set the symbol for display purposes
  30. }
  31. function transfer(address _to, uint256 _value) public returns (bool success) {
  32. require(balances[msg.sender] >= _value);
  33. balances[msg.sender] -= _value;
  34. balances[_to] += _value;
  35. Transfer(msg.sender, _to, _value);
  36. return true;
  37. }
  38. function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
  39. uint256 allowance = allowed[_from][msg.sender];
  40. require(balances[_from] >= _value && allowance >= _value);
  41. balances[_to] += _value;
  42. balances[_from] -= _value;
  43. if (allowance < MAX_UINT256) {
  44. allowed[_from][msg.sender] -= _value;
  45. }
  46. Transfer(_from, _to, _value);
  47. return true;
  48. }
  49. function balanceOf(address _owner) public view returns (uint256 balance) {
  50. return balances[_owner];
  51. }
  52. function approve(address _spender, uint256 _value) public returns (bool success) {
  53. allowed[msg.sender][_spender] = _value;
  54. Approval(msg.sender, _spender, _value);
  55. return true;
  56. }
  57. function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
  58. return allowed[_owner][_spender];
  59. }
  60. }