0

Lets say i have contract that has couple functions which i want to call them by my other contracts, so i add some modifiers which help to doing this and.

For interacting with my contract i use interface, But the question is that inside interface there is no modifiers, if someone called functions of my contract using interface, do modifiers revert this function or not??? here is my function in contract:

function updateUserBalances(uint256 amount, address userAddress, address tokenAddress) external onlyPair{
    _updateUserBalances(amount, userAddress, tokenAddress;
}

and here function in interface:

function updateUserBalances (uint256 amount, address userAddress, address tokenAddress) external;

2 Answers 2

1

The reasoning behind using Solidity interfaces when you interact with a contract externally is that you just need to have a blueprint of the contract external functions signatures. This allows you to build correct calls to each type of function, using the correct calldata, etc.

Modifiers are part of the implementation of each function. They actually modify the function to include the extra lines before and after the _;.

This means that whenever you call the contract, through an interface or by direct call with signature, the implementation will check whatever modifiers you have compiled in the contract itself.

2
  • So it means that it is secure to put my function as a external function and call them by my other contracts? imagine i'm updating balance of users using this function ant it's very important that anyone else can not call this function except the contract which i entered in modifier before.
    – Alireza
    Jan 22, 2023 at 17:47
  • Yes, because the modifier will execute. If the function needs to be accessible to other external contracts, then it needs to be external.
    – prc
    Jan 24, 2023 at 9:06
0

Yes your called function will use the added modifier.

The purpose of Interface is to simplify calling the implementation of other functions, but it doesn't change the initial functionality (for example modifiers)

The of modifiers wouldn't work only if you would override the function.

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.