0

This is just part of my contract, but shows where I create the mapping, the modifier onlyMember, and the function addMember. Basically, I want to be able to add new members who can execute onlyMember functions, as I - the owner - can. I was able to add a new member, as the owner, but when I switched to the member address and tried to execute other functions that appear later in the contract (which have the modifier onlyMember attached to them), I get an error. I am wondering if I set up the addMember function incorrectly, but remix isn't giving me any errors about it.

// <------------------------- MEMBERS ------------------------->

address owner = msg.sender;
bool ifmember;
mapping(address => bool) members;

modifier onlyMember {
    require(msg.sender == owner || members[msg.sender] == true);
    _;
    }

function addMember(address _address) public onlyMember {
    ifmember = members[_address];
    }

// <----------------------- END MEMBERS ----------------------->

1 Answer 1

3

There's nothing syntactically wrong with your addMember function so Remix won't give you any errors, but it's not really doing anything.

This line:

ifmember = members[_address];

is just setting the variable ifmember equal to the value of members[_address]. In the code you provided there's nothing changing the value of members[_address].

I'm not sure what ifmember is supposed to be doing, but I tihnk you want this for your addMember function:

function addMember(address _address) public onlyMember {
    members[_address] = true;
}
1
  • Thank you. I am new to bools and thought I had to declare it before using it. Commented May 30, 2018 at 3:38

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.