How would I write the interface equivalent of this function?

Link (create function):

function create(
        string memory name,
        string memory symbol,
        IERC20[] memory tokens,
        uint256[] memory normalizedWeights,
        IRateProvider[] memory rateProviders,
        uint256 swapFeePercentage,
        address owner
    ) external returns (address)


function create(string calldata name,
        string calldata symbol,
        IERC20[] calldata tokens,
        uint256[] calldata normalizedWeights,
        IRateProvider[] calldata rateProviders,
        uint256 swapFeePercentage,
        address owner) external returns (address);

Just wanted to double check since I've never had to write an interface equivalent for a complicated function.

As far as I can see, you've replicated the function declaration, and then replaced every occurrence of memory with calldata.

The reason for that is unclear to me, because 'memory vs calldata' has no "special meaning" related to interfaces.

The calldata keyword is used for indicating that the pointed input data is read-only (cannot be modified inside the function), which allows for some minor gas optimization.

A calldata input argument can be passed to a function either from another function which has received it as calldata, or from the offchain.

In other words, you cannot create a calldata object inside a contract function.

You can read the basic facts about interfaces here (see TLDR below).

You can interact with other contracts by declaring an interface:

  • It cannot have any functions implemented
  • It can inherit from other interfaces
  • All declared functions must be external
  • It cannot declare a constructor
  • It cannot declare state variables

As you can see, nothing specifically related to 'memory vs calldata'.


Other than gas optimization, receiving an input as calldata allows you to apply "fancy tricks" on it, such as array slicing, which you cannot apply on memory.

Hello barakman.
Can we discuss in detail about the smart contract?
Your answers are always correct.


Thank you :slight_smile:

What do you want to discuss?

Do you have ongoing project?

Yes - at Bancor.

You can find my TG address via developer wanted post.
Please contact me via TG