0

I am new to solidity so I just started with the voting example in the solidity docs.I am clear with the smart contract but there is a sub-section stating possible improvements - "Currently, many transactions are needed to assign the rights to vote to all participants. Can you think of a better way?"

So,what changes do I need to make in the giveRightToVote function for reducing the transactions ?

function giveRightToVote(address voter) external {
        
        require(
            msg.sender == chairperson,
            "Only chairperson can give right to vote."
        );
        require(
            !voters[voter].voted,
            "The voter already voted."
        );
        require(voters[voter].weight == 0);
        voters[voter].weight = 1;
    }
1
  • So instead of assigning one by one what other options can you imagine?
    – Ismael
    Commented Feb 22, 2022 at 21:50

1 Answer 1

0

I've expanded a bit on the contract as per the proposed improvements.

Take a look at https://github.com/kristofvdj88/solidity-by-example/tree/main/voting

1
  • Hi kristofvdj88! Welcome to Ethereum Stackexchange! Link only answers are discouraged. It is better to put the main idea in the answer and use the link to expand the details.
    – Ismael
    Commented Oct 8, 2022 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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