1

What are the parameters required to deploy the Ballot contract given in the solidity manual http://solidity.readthedocs.io/en/develop/solidity-by-example.html?

When I deploy new contract using Ethereum Wallet it asks me to enter constructor parameters as below:

enter image description here

I have tried option ['ballot1', 111] and the contract is successfully deployed. But when I check the contract info with 111 its not showing up any info of that proposal

I'm not understanding what parameters to be given and how to check the working of Ballot contract.

  • Can you add a few more details to your question? What exactly do you mean by "parameters"? Have you tried anything so far? – Richard Horrocks Mar 5 '17 at 19:56
  • I have edited the question. Let me know if any additional info is required. – snehal Mar 5 '17 at 20:19
  • 1
    Have you clearly understood the working of Ballot contract? – Aniket Mar 6 '17 at 7:41
1

This perhaps isn't the best example to start with. The very first line on the page you link to says this:

The following contract is quite complex, but showcases a lot of Solidity’s features.

When the contract is created/deployed, its constructor function is called. (The function with the same name as the contract.)

function Ballot(bytes32[] proposalNames) {
        chairperson = msg.sender;
        voters[chairperson].weight = 1;

        // For each of the provided proposal names,
        // create a new proposal object and add it
        // to the end of the array.
        for (uint i = 0; i < proposalNames.length; i++) {
            // `Proposal({...})` creates a temporary
            // Proposal object and `proposals.push(...)`
            // appends it to the end of `proposals`.
            proposals.push(Proposal({
                name: proposalNames[i],
                voteCount: 0
            }));
        }
    }

This takes an array of bytes32, called proposalNames, as an argument.

If you look at what the function is doing, it loops through the array of names and adds each one to an array of objects. Note that it sets the vote count of each to 0. All subsequent operations - setting and getting - will access these objects.

Using your example, I deployed the contract using "ballot1", 111 as the proposal names. (Having a number as a proposal name is a bit confusing, but it should still work.)

I then voted numerous times using the vote() function by passing the proposal number (either 0 or 1).

Calling proposals() and passing 0 or 1 allows you to check the current number of votes for that proposal. You can't use the proposal name to query this (at least in this contract).

And finally, calling winningProposal() returns the number of the proposal that has the most votes.

If you're just starting off, you might find using Browser Solidity easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.