2

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

2
  • Get rid of that 16 and you should be fine. Dec 30, 2018 at 18:41
  • It still throws the same error even when I remove that Dec 30, 2018 at 19:40

1 Answer 1

3

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;

} 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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