I'm using:

 pragma solidity ^0.5.0;

I have a function as below in my contract:

function test(string a) external{

An error shows up saying I need to add "calldata" to the parameter. So, if I do the following the error disappears:

function test(string calldata a) external{

Question: Why do I need to add "calldata" when I use string type as a parameter?


Explicit data location for all variables of struct, array or mapping types is now mandatory. This is also applied to function parameters and return variables. For example, change uint[] x = m_x to uint[] storage x = m_x, and function f(uint[][] x) to function f(uint[][] memory x) where memory is the data location and might be replaced by storage or calldata accordingly. Note that external functions require parameters with a data location of calldata. for more Info

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.