I can already implement a basic onlyOwner modifier. But what if I have an onlyOwner modifer already in my function and I want to specify that a function can be called by anyone other than the owner in the same contract. Would I have to write a separate modifier, or does solidity build in something like myFunction() !onlyOwner {...] that I could use instead?

  • why to use the modifier then?:!!!
    – Badr Bellaj
    Jun 10 '17 at 17:34
  • 1
    because I'm still restricting who can call my function based on the address of the caller. It's like if I have a modifier that says only Eve can call a function, and not Bob or Alice. By inverting it, I say that Bob and Alice can call the function, but not Eve. Which I could do with a separate modifier, but that would require me to write a separate modifer, when I just want to invert the restriction provided by the original
    – user9402
    Jun 10 '17 at 18:02

Modifiers can be used to do lots of things.

With the onlyOwner modifier the result of inverting might be pretty obvious, but with more involved modifiers an inversion or negation would likely be more complex, meaning ! would act to obfuscate or make confusing the inverted modifier's function.

Noting that code is usually "written once, read many times", it's in the best interest of the code writer to make it as clear as possible when it's first written.

  • So it is possible then to use ! with an existing modifier to invert the condition?
    – user9402
    Jun 10 '17 at 19:17

Your Answer

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