3

I get this error when I try to paste the democracy contract code in solidity:

Unused local variable
        Member m = members[id];
2

(Edit: I hadn't realised the Wallet treats warnings as errors.)

This is shown as a Warning in Remix, rather than an Error - it shouldn't stop the contract from compiling. If you're using the Ethereum Wallet, the unused variable stops the contract being deployed.


However... The contract code on that page seems to have changed at some point. That block of code used to look like this:

function changeMembership(address targetMember, bool canVote, string memberName) onlyOwner {
        uint id;
        if (memberId[targetMember] == 0) {
           memberId[targetMember] = members.length;
           id = members.length++;
           members[id] = Member({member: targetMember, canVote: canVote, memberSince: now, name: memberName});
        } else {
            id = memberId[targetMember];
            Member m = members[id];
            m.canVote = canVote;
        }

        MembershipChanged(targetMember, canVote);

    }

Where the function was called changeMembership(), and we passed in the canVote boolean. Instead we now have addMember() and removeMember(), but it seems the Member M line has been left behind.

I'd recommend changing the code from this:

   /*make member*/
    function addMember(address targetMember, string memberName) onlyOwner {
        uint id;
        if (memberId[targetMember] == 0) {
           memberId[targetMember] = members.length;
           id = members.length++;
           members[id] = Member({member: targetMember, memberSince: now, name: memberName});
        } else {
            id = memberId[targetMember];
            Member m = members[id];
        }

        MembershipChanged(targetMember, true);
    }

...to the following:

function addMember(address targetMember, string memberName) onlyOwner {
    uint id;
    if (memberId[targetMember] == 0) {
        memberId[targetMember] = members.length;
        id = members.length++;
        members[id] = Member({member: targetMember, memberSince: now, name: memberName});
        MembershipChanged(targetMember, true);
    }
}

Remember, these code samples are only examples - you shouldn't rely on them for correctness, nor should you send the payable functions anything of real value until you're absolutely certain you know how it all works.

  • If you use the ethereum wallet it doesn't let you deploy the contract – Joe Jun 28 '17 at 13:07
  • Aha, okay - thanks. What does it do exactly? – Richard Horrocks Jun 28 '17 at 13:14
  • Also could you clarify which part of the contract your new code replaces. I assumed from after uint id until the final } from the excerpt you copied. I tried that and the error does go away – Joe Jun 28 '17 at 13:59
  • Okay, the Ethereum Wallet must have more stringent checks than Remix. The Wallet must treat a Warning as an Error. I've updated my answer to clarify which bit of code to change. (But yes, you are correct.) – Richard Horrocks Jun 28 '17 at 14:10

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.