Why does batchMint use memory for parameters?

In the batchMint() function of the erc1155 contract, the batchMint() function use memory for the parameters.

 function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        _mintBatch(to, ids, amounts, data);

Wouldn't it be more gas efficient to use calldata instead?

Hey @Dimitri_Borgers, welcome to the community and thanks for your question :slight_smile:

In regards to the calldata vs memory, yes, it’d be more efficient but improvements overall are less than 1% and there are usage considerations about using calldata instead.

You can see the discussion in Github, particularly in this comment, you’ll find an explanation about that.

The answer is that calldata can’t be built during execution when sending it to another contract, so you couldn’t pass a parameter correctly because the only way is via memory.

Hope this helps.

1 Like

Super helpful, thank you!