Guest User

Untitled

a guest
Jan 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. uint256 constant private MAX_UINT256 = 2**256 - 1;
  2. mapping (address => uint256) public balances;
  3. mapping (address => mapping (address => uint256)) public allowed;
  4. /*
  5. NOTE:
  6. The following variables are OPTIONAL vanities. One does not have to include them.
  7. They allow one to customise the token contract & in no way influences the core functionality.
  8. Some wallets/interfaces might not even bother to look at this information.
  9. */
  10. string public name; //fancy name: eg Simon Bucks
  11. uint8 public decimals; //How many decimals to show.
  12. string public symbol; //An identifier: eg SBX
  13.  
  14. function BERToken(
  15. uint256 _initialAmount,
  16. string _tokenName,
  17. uint8 _decimalUnits,
  18. string _tokenSymbol
  19. ) public {
  20. balances[msg.sender] = _initialAmount; // Give the creator all initial tokens
  21. totalSupply = _initialAmount; // Update total supply
  22. name = _tokenName; // Set the name for display purposes
  23. decimals = _decimalUnits; // Amount of decimals for display purposes
  24. symbol = _tokenSymbol; // Set the symbol for display purposes
  25. }
  26.  
  27. function transfer(address _to, uint256 _value) public returns (bool success) {
  28. require(balances[msg.sender] >= _value);
  29. balances[msg.sender] -= _value;
  30. balances[_to] += _value;
  31. emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars
  32. return true;
  33. }
  34.  
  35. function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
  36. uint256 allowance = allowed[_from][msg.sender];
  37. require(balances[_from] >= _value && allowance >= _value);
  38. balances[_to] += _value;
  39. balances[_from] -= _value;
  40. if (allowance < MAX_UINT256) {
  41. allowed[_from][msg.sender] -= _value;
  42. }
  43. emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars
  44. return true;
  45. }
  46.  
  47. function balanceOf(address _owner) public view returns (uint256 balance) {
  48. return balances[_owner];
  49. }
  50.  
  51. function approve(address _spender, uint256 _value) public returns (bool success) {
  52. allowed[msg.sender][_spender] = _value;
  53. emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars
  54. return true;
  55. }
  56.  
  57. function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
  58. return allowed[_owner][_spender];
  59. }
Add Comment
Please, Sign In to add comment