1

Today I found a contract on etherscan providing a restriction on one of the two existing "withdraw" methods and I asked myself: If you would call this function withdraw() as not the owner, will the restriction apply anyways, cause it is calling a restricted function?

  function withdraw() public {
    // delegate to `withdrawTo`
    withdrawTo(msg.sender);
  }

  function withdrawTo(address _to) public onlyOwner {
    require(_to != address(0), "address not set");
    uint256 value = address(this).balance;
    require(value > 0, "zero balance");
    uint256 developerFee = value / 33;
    value -= developerFee;
    payable(_to).transfer(value);
    payable(developerAddress).transfer(developerFee);
    emit Withdrawn(msg.sender, _to, address(this).balance);

1 Answer 1

2

Yes, the modifiers will work even if the function is called inside another function.

I have tested it in Remix and the function seems to work as intended, and only the owner can use it.

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.