However is it okay to define a public function in its interface as external?
No, you cannot do that in an interface. As per the Solidity documentation:
Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions:
- ...
- All declared functions must be external.
- ...
But what you can do is define your interface like this:
interface MyInterface {
function foo(bytes calldata b) external view returns (bool);
}
And your contract like this:
import "./MyInterface.sol";
contract MyContract is MyInterface {
function foo(bytes memory b) public view returns (bool) {
...
}
}
Note: there are two additional parameters, virtual and override, to be cognizant of if you're using Solidity v6 or above. Read this thread for more info.