Guest User

Untitled

a guest
Feb 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. pragma solidity ^0.4.19;
  2.  
  3. contract ICO {
  4. address public owner;
  5. mapping(address => uint) public balances;
  6. address[] public buyers;
  7.  
  8. uint constant public MULTIPLIER = 1000;
  9.  
  10. function ICO() public {
  11. owner = msg.sender;
  12. }
  13.  
  14. function getBuyersLength() public constant returns (uint) {
  15. return buyers.length;
  16. }
  17.  
  18. function buy() public payable {
  19. uint coins = msg.value * MULTIPLIER;
  20. balances[msg.sender] += coins;
  21. buyers.push(msg.sender);
  22. }
  23. }
  24.  
  25. function main() {
  26. let contract = web3.eth.contract(CONTRACT_ABI).at(CONTRACT_ADDR);
  27. let amount = w3.toWei(10, 'ether');
  28. contract.buy({'value': amount}, function (err, res) {
  29. if (err) {
  30. console.error('Error occurred: ' + err);
  31. } else {
  32. console.log('Transaction created: ' + res);
  33. }
  34. })
  35. }
  36.  
  37. function updateBalances() {
  38. contract.getBuyersLength(function (err, res) {
  39. if (err) {
  40. console.error('Error in getBuyers: ' + err);
  41. } else {
  42. console.log('Count of Buyers: ' + res);
  43. }
  44. }
  45. }
Add Comment
Please, Sign In to add comment