1

Can I use onlyOwner() and onlyOwner modifier calls interchangeably in Solidity?

Is there any particular difference between these 2 functions below considering that

address owner;

constructor() {
    owner = msg.sender;
}

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

2 different ways of attaching the modifier:

function buyPet(uint petId) external onlyOwner() {
        // ... some logic
 }




function buyPet(uint petId) external onlyOwner {
        // ... some logic
 }

Please advice!

1 Answer 1

3

Both are the same, brackets are more often used when we need to pass arguments to the modifier. Else normally we don't use brackets.

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.