I know that is question has been answered in one form. However, I could not find an answer for my specific case.

Here is my code:

pragma solidity ^0.5.0;

contract Adoption {
 address[16] adopters;

//Adopting a Pet
function adopt(uint petId) public returns (uint){
  require(petId >= 0 && petId <= 15);
  adopters[petId] = msg.sender;
  return petId;

// Retrieving the adopters
function getAdopters() public view returns (address[16]){
 return adopters;


Right now this is throwing a

TypeError: Data location must be "memory" for return parameter in function

but none was given error and the error is originating from

function getAdopters() public view returns (***address[16]***){

From my understanding, memory is just a key word that creates a temporary variable. Do I need to use a storage variable for the public address array?

I am going based off of this tutorial: https://truffleframework.com/tutorials/pet-shop

  • Get rid of that 16 and you should be fine. – goodvibration Dec 30 '18 at 18:41
  • It still throws the same error even when I remove that – Grant Herman Dec 30 '18 at 19:40

Use memory storage For return struct or array types of data is good practice and it improves the performance of code and from solidity version 0.5.0, it is compulsory to use memory storage for this type of data types.

You have to just put memory keyword in return parameter of function getAdopters() like this:

function getAdopters() public view returns (address[16] memory){

     return adopters;


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.