TypeError: Data location can only be specified for array, struct or mapping types, but "calldata" was given

Viewed 563

I created a function that stores data. But this function cannot receive data. I tried it without calldata, with memory but all this ways didn't work. Thanks for the help.

pragma solidity >=0.7.0 <0.9.0;
contract Test {
struct Messanges{
    string message;
    address sender;
}
Messanges[] public chatverlauf;
address a = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
function add(string calldata _message, address calldata _sender) public{
    //chatverlauf.push(Messanges(_message, _sender));
    Messanges memory newMessage;
    newMessage.message = _message;
    newMessage.sender = _sender;
    chatverlauf.push(newMessage);

}

i lookt up in this but it didn't workt for me

https://ethereum.stackexchange.com/questions/83602/data-location-can-only-be-specified-for-array-struct-or-mapping-types-but-mem/83603

written with remix the compiler version is 0.8.10

1 Answers

change

function add(string calldata _message, address calldata _sender) public

to

function add(string _message, address _sender) public

In Solidity 0.8.0 only array , struct and mapping type can specific data location.

Related