Guest User

ERC20_Distribution

a guest
Nov 9th, 2017
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Following is a sample token contract with a fixed supply of 1000000 units that are initially assigned to the owner of the contract:
  2. pragma solidity ^0.4.8;
  3. contract ERC20Interface
  4. {
  5. function totalSupply() constant returns (uint256 totalSupply);
  6. function balanceOf(address _owner) constant returns (uint256 balance);
  7. function transfer(address _to, uint256 _value) returns (bool success);
  8. function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
  9. function approve(address _spender, uint256 _value) returns (bool success);
  10. function allowance(address _owner, address _spender) constant returns (uint256 remaining);
  11. event Transfer(address indexed _from, address indexed _to, uint256 _value);
  12. event Approval(address indexed _owner, address indexed _spender, uint256 _value);
  13. }
  14.  
  15. contract FixedSupplyToken is ERC20Interface
  16. {
  17. string public constant symbol = "FIXED";
  18. string public constant name = "Example Fixed Supply Token";
  19. uint8 public constant decimals = 18;
  20. uint256 _totalSupply = 1000000;
  21.  
  22. // Owner of this contract
  23. address public owner;
  24.  
  25. // Balances for each account
  26. mapping(address => uint256) balances;
  27.  
  28. // Owner of account approves the transfer of an amount to another account
  29. mapping(address => mapping (address => uint256)) allowed;
  30.  
  31. // Functions with this modifier can only be executed by the owner
  32. modifier onlyOwner() {
  33. if (msg.sender != owner) {
  34. throw;
  35. }
  36. _;
  37. }
  38.  
  39. // Constructor
  40. function FixedSupplyToken() {
  41. owner = msg.sender;
  42. balances[owner] = _totalSupply;
  43. }
  44.  
  45. function totalSupply() constant returns (uint256 totalSupply) {
  46. totalSupply = _totalSupply;
  47. }
  48.  
  49. // What is the balance of a particular account?
  50. function balanceOf(address _owner) constant returns (uint256 balance) {
  51. return balances[_owner];
  52. }
  53.  
  54. // Transfer the balance from owner's account to another account
  55. function transfer(address _to, uint256 _amount) returns (bool success) {
  56. if (balances[msg.sender] >= _amount
  57. && _amount > 0
  58. && balances[_to] + _amount > balances[_to]) {
  59. balances[msg.sender] -= _amount;
  60. balances[_to] += _amount;
  61. Transfer(msg.sender, _to, _amount);
  62. return true;
  63. } else {
  64. return false;
  65. }
  66. }
  67.  
  68. function transferFrom(
  69. address _from,
  70. address _to,
  71. uint256 _amount
  72. ) returns (bool success) {
  73. if (balances[_from] >= _amount
  74. && allowed[_from][msg.sender] >= _amount
  75. && _amount > 0
  76. && balances[_to] + _amount > balances[_to]) {
  77. balances[_from] -= _amount;
  78. allowed[_from][msg.sender] -= _amount;
  79. balances[_to] += _amount;
  80. Transfer(_from, _to, _amount);
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. }
  86.  
  87. // Allow _spender to withdraw from your account, multiple times, up to the _value amount.
  88. // If this function is called again it overwrites the current allowance with _value.
  89. function approve(address _spender, uint256 _amount) returns (bool success) {
  90. allowed[msg.sender][_spender] = _amount;
  91. Approval(msg.sender, _spender, _amount);
  92. return true;
  93. }
  94.  
  95. function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
  96. return allowed[_owner][_spender];
  97. }
  98. //Distribute Function for sending equal amount of the token to an array of addresses
  99. function distributeToken(address[] addresses, uint256 _value) onlyOwner
  100. {
  101. for (uint i = 0; i < addresses.length; i++) {
  102. balances[owner] -= _value;
  103. balances[addresses[i]] += _value;
  104. Transfer(owner, addresses[i], _value);
  105. }
  106. }
  107. }
RAW Paste Data