I started my first code in solidity . when i was implemented getter and setter i have face some error .

The Following code,

pragma solidity ^0.5.0;

contract MyFirstContract{
    string private name;
    uint private age;

    function setName(string newName) public{
    function getName()public view returns(string){
        return name;

    function setAge(uint newAge) public{
    function getAge()public view returns(uint){
        return age;


Error 1:

browser/MyFirstContract.sol:7:22: TypeError: Data location must be "memory" for parameter in function, but none was given.
    function setName(string newName) public{

Error 2:

browser/MyFirstContract.sol:10:43: TypeError: Data location must be "memory" for return parameter in function, but none was given.
    function getName()public view returns(string){

marked as duplicate by Ismael, shane, GrandFleet, Achala Dissanayake, Richard Horrocks Dec 19 '18 at 10:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You need to give memory keyword to your code function string parameter like this:

function setName(string memory newName) public{

and also for return string parameter

function getName()public view returns(string memory){

  • Thank you . Can you suggest some tutorial where i can learn blockchain related video tutorial – Boxer Robert Dec 14 '18 at 8:56
  • If you want to learn solidity from the beginning then watch this tutorial series link and latest changes from link. If you want to learn about blockchain than you get many videos on the internet and then you have to decide that with which platform(ethereum,hyperledger,eosio,etc..) you want to go for development. – Mahesh Rajput Dec 14 '18 at 9:05
  • It’s a breaking change that was introduced in 0.50. If you use a lower version this should work – Samuel Dare Dec 14 '18 at 13:31
  • @MaheshRajput Perfect already i started to follow that tutorial only – Boxer Robert Dec 15 '18 at 0:45

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