Guest User

Untitled

a guest
Aug 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. pragma solidity ^0.4.16;
  2.  
  3. // ----------------------------------------------------------------------------
  4. //
  5. //
  6. // Deployed to : 0x240083ca1a2C5aF0914091645108B67eb14f7934
  7. // Symbol : STR1CO
  8. // Name : String 1Token
  9. // Total supply: Gazillion
  10. // Decimals : 18
  11. //
  12. // ----------------------------------------------------------------------------
  13.  
  14. contract owned {
  15. address public owner;
  16.  
  17. constructor() public {
  18. owner = msg.sender;
  19. }
  20.  
  21. modifier onlyOwner {
  22. require(msg.sender == owner);
  23. _;
  24. }
  25.  
  26. function transferOwnership(address newOwner) onlyOwner public {
  27. owner = newOwner;
  28. }
  29. }
  30.  
  31. interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }
  32.  
  33. contract String1Token {
  34. // Public variables of the token
  35. string public name;
  36. string public symbol;
  37. uint8 public decimals = 18;
  38. // 18 decimals is the strongly suggested default, avoid changing it
  39. uint256 public totalSupply;
  40.  
  41. // This creates an array with all balances
  42. mapping (address => uint256) public balanceOf;
  43. mapping (address => mapping (address => uint256)) public allowance;
  44.  
  45. // This generates a public event on the blockchain that will notify clients
  46. event Transfer(address indexed from, address indexed to, uint256 value);
  47.  
  48. // This generates a public event on the blockchain that will notify clients
  49. event Approval(address indexed _owner, address indexed _spender, uint256 _value);
  50.  
  51. // This notifies clients about the amount burnt
  52. event Burn(address indexed from, uint256 value);
  53.  
  54. /**
  55. * Constrctor function
  56. *
  57. * Initializes contract with initial supply tokens to the creator of the contract
  58. */
  59. constructor (
  60. uint256 initialSupply,
  61. string tokenName,
  62. string tokenSymbol
  63. ) public {
  64. totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
  65. balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
  66. name = tokenName; // Set the name for display purposes
  67. symbol = tokenSymbol; // Set the symbol for display purposes
  68. }
  69.  
  70. /**
  71. * Internal transfer, only can be called by this contract
  72. */
  73. function _transfer(address _from, address _to, uint _value) internal {
  74. // Prevent transfer to 0x0 address. Use burn() instead
  75. require(_to != 0x0);
  76. // Check if the sender has enough
  77. require(balanceOf[_from] >= _value);
  78. // Check for overflows
  79. require(balanceOf[_to] + _value > balanceOf[_to]);
  80. // Save this for an assertion in the future
  81. uint previousBalances = balanceOf[_from] + balanceOf[_to];
  82. // Subtract from the sender
  83. balanceOf[_from] -= _value;
  84. // Add the same to the recipient
  85. balanceOf[_to] += _value;
  86. emit Transfer(_from, _to, _value);
  87. // Asserts are used to use static analysis to find bugs in your code. They should never fail
  88. assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
  89. }
  90.  
  91. /**
  92. * Transfer tokens
  93. *
  94. * Send `_value` tokens to `_to` from your account
  95. *
  96. * @param _to The address of the recipient
  97. * @param _value the amount to send
  98. */
  99. function transfer(address _to, uint256 _value) public returns (bool success) {
  100. _transfer(msg.sender, _to, _value);
  101. return true;
  102. }
  103.  
  104. /**
  105. * Transfer tokens from other address
  106. *
  107. * Send `_value` tokens to `_to` in behalf of `_from`
  108. *
  109. * @param _from The address of the sender
  110. * @param _to The address of the recipient
  111. * @param _value the amount to send
  112. */
  113. function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
  114. require(_value <= allowance[_from][msg.sender]); // Check allowance
  115. allowance[_from][msg.sender] -= _value;
  116. _transfer(_from, _to, _value);
  117. return true;
  118. }
  119.  
  120. /**
  121. * Set allowance for other address
  122. *
  123. * Allows `_spender` to spend no more than `_value` tokens in your behalf
  124. *
  125. * @param _spender The address authorized to spend
  126. * @param _value the max amount they can spend
  127. */
  128. function approve(address _spender, uint256 _value) public
  129. returns (bool success) {
  130. allowance[msg.sender][_spender] = _value;
  131. emit Approval(msg.sender, _spender, _value);
  132. return true;
  133. }
  134.  
  135. /**
  136. * Set allowance for other address and notify
  137. *
  138. * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
  139. *
  140. * @param _spender The address authorized to spend
  141. * @param _value the max amount they can spend
  142. * @param _extraData some extra information to send to the approved contract
  143. */
  144. function approveAndCall(address _spender, uint256 _value, bytes _extraData)
  145. public
  146. returns (bool success) {
  147. tokenRecipient spender = tokenRecipient(_spender);
  148. if (approve(_spender, _value)) {
  149. spender.receiveApproval(msg.sender, _value, this, _extraData);
  150. return true;
  151. }
  152. }
  153.  
  154. /**
  155. * Destroy tokens
  156. *
  157. * Remove `_value` tokens from the system irreversibly
  158. *
  159. * @param _value the amount of money to burn
  160. */
  161. function burn(uint256 _value) public returns (bool success) {
  162. require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
  163. balanceOf[msg.sender] -= _value; // Subtract from the sender
  164. totalSupply -= _value; // Updates totalSupply
  165. emit Burn(msg.sender, _value);
  166. return true;
  167. }
  168.  
  169. /**
  170. * Destroy tokens from other account
  171. *
  172. * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
  173. *
  174. * @param _from the address of the sender
  175. * @param _value the amount of money to burn
  176. */
  177. function burnFrom(address _from, uint256 _value) public returns (bool success) {
  178. require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
  179. require(_value <= allowance[_from][msg.sender]); // Check allowance
  180. balanceOf[_from] -= _value; // Subtract from the targeted balance
  181. allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
  182. totalSupply -= _value; // Update totalSupply
  183. emit Burn(_from, _value);
  184. return true;
  185. }
  186. }
Add Comment
Please, Sign In to add comment