0

I had some function like withdraw and self-destruct functions set as internal, but I can't call them from "Mist", then I turned them to public but I set the modifier :

modifier isOwner() {
if (msg.sender != owner) _; 
}

Then added isOwner to my functions

function kill() isOwner public {
    selfdestruct(beneficiary);
} 

But when I try to call it from a subaccount (not the owner account) it works!

1

You should change your modifier to something like

modifier isOwner {
  require(msg.sender == owner);
  _;
 }

In your case the if is checking if msg.sender is not equal to owner , if true then it continue the execution of the code.

You mentionned that you tried to set your functions as internal and could not call them via mist => It's normal , functions marked as internal can only be called inside the contract itself or contract deriving it ( as per the official doc) as far as I know .

  • Thank you Tbrunain for your reply, So the only way to protect withdraw functions is to protect them with isOwner modifier ? if there is any other way please do share it with me – ONE FANCY APPS Dec 10 '17 at 16:19
  • As far as I know yeah (please someone correct me if I'm wrong) , if you want to have a withdraw function and restrict its usage to only the owner , then a modifier is the way to go . Note that you can as well skip the modifier and put the require(msg.sender == owner) directly in the body of your withdraw function . – tbrunain Dec 10 '17 at 16:39

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.