0

I'm using:

 pragma solidity ^0.5.0;

I have a function as below in my contract:

function test(string a) external{
  a="apple";
}

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{
  a="apple";
}

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

2

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 agree to our terms of service, privacy policy and cookie policy

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