Solidity – How to Define a Public Function in a Solidity Interface

solidity

It seems all function definitions in an interface must be external. However is it okay to define a public function in its interface as external? If so, how can I define a public function that takes a bytes memory?

for example, How could I write an interface for this contract:

contract C {
  function a(bytes memory b) public view returns (bool) {
    return true;
  }
}

Best Answer

This should work:

interface C {
  function a(bytes calldata b) external view returns (bool);
}

A public function can handle being called from inside the contract or outside, so it sort of has two interfaces. The internal one uses memory for the parameters' location, but the external interface uses call data.

Related Topic