Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.19;
- contract ICO {
- address public owner;
- mapping(address => uint) public balances;
- address[] public buyers;
- uint constant public MULTIPLIER = 1000;
- function ICO() public {
- owner = msg.sender;
- }
- function getBuyersLength() public constant returns (uint) {
- return buyers.length;
- }
- function buy() public payable {
- uint coins = msg.value * MULTIPLIER;
- balances[msg.sender] += coins;
- buyers.push(msg.sender);
- }
- }
- function main() {
- let contract = web3.eth.contract(CONTRACT_ABI).at(CONTRACT_ADDR);
- let amount = w3.toWei(10, 'ether');
- contract.buy({'value': amount}, function (err, res) {
- if (err) {
- console.error('Error occurred: ' + err);
- } else {
- console.log('Transaction created: ' + res);
- }
- })
- }
- function updateBalances() {
- contract.getBuyersLength(function (err, res) {
- if (err) {
- console.error('Error in getBuyers: ' + err);
- } else {
- console.log('Count of Buyers: ' + res);
- }
- }
- }
Add Comment
Please, Sign In to add comment