Skip to content
nieves01 edited this page Dec 24, 2016 · 1 revision

`chdir

open geth.exe`

contract mortal { /* Define variable owner of the type address*/ address owner;

/* this function is executed at initialization and sets the owner of the contract */
function mortal() { owner = msg.sender; }

/* Function to recover the funds on the contract */
function kill() { if (msg.sender == owner) selfdestruct(owner); }

}

contract greeter is mortal { /* define variable greeting of the type string */ string greeting;

/* this runs when the contract is executed */
function greeter(string _greeting) public {
    greeting = _greeting;
}

/* main function */
function greet() constant returns (string) {
    return greeting;
}

} pragma solidity ^0.4.0; contract Ballot {

struct Voter {
    uint weight;
    bool voted;
    uint8 vote;
    address delegate;
}
struct Proposal {
    uint voteCount;
}

address chairperson;
mapping(address => Voter) voters;
Proposal[] proposals;

/// Create a new ballot with $(_numProposals) different proposals.
function Ballot(uint8 _numProposals) {
    chairperson = msg.sender;
    voters[chairperson].weight = 1;
    proposals.length = _numProposals;
}

/// Give $(voter) the right to vote on this ballot.
/// May only be called by $(chairperson).
function giveRightToVote(address voter) {
    if (msg.sender != chairperson || voters[voter].voted) return;
    voters[voter].weight = 1;
}

/// Delegate your vote to the voter $(to).
function delegate(address to) {
    Voter sender = voters[msg.sender]; // assigns reference
    if (sender.voted) return;
    while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
        to = voters[to].delegate;
    if (to == msg.sender) return;
    sender.voted = true;
    sender.delegate = to;
    Voter delegate = voters[to];
    if (delegate.voted)
        proposals[delegate.vote].voteCount += sender.weight;
    else
        delegate.weight += sender.weight;
}

/// Give a single vote to proposal $(proposal).
function vote(uint8 proposal) {
    Voter sender = voters[msg.sender];
    if (sender.voted || proposal >= proposals.length) return;
    sender.voted = true;
    sender.vote = proposal;
    proposals[proposal].voteCount += sender.weight;
}

function winningProposal() constant returns (uint8 winningProposal) {
    uint256 winningVoteCount = 0;
    for (uint8 proposal = 0; proposal < proposals.length; proposal++)
        if (proposals[proposal].voteCount > winningVoteCount) {
            winningVoteCount = proposals[proposal].voteCount;
            winningProposal = proposal;
        }
}

} var _greeting = "Hello World!" var greeterContract = web3.eth.contract(greeterCompiled.greeter.info.abiDefinition);

var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0], data: greeterCompiled.greeter.code, gas: 300000}, function(e, contract){ if(!e) {

  if(!contract.address) {
    console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");

  } else {
    console.log("Contract mined! Address: " + contract.address);
    console.log(contract);
  }

}

})

Clone this wiki locally