How to return array of address in solidity?Solidity - Filling and using array of arrayError: Method eth_compileSolidity not supportedWeb3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of structupgradable smart contracts with Solidity: interface vs library?Expected Primary Expression (Solidity)browser/ballot.sol:102:18: ParserError: Expected '{' but got identifier contract token is ERC20Interface, Owned, SafeMath { ^----^Function error with my Solidity map(int,string) while using javascript to return values to html.Can I use my custom ERC-20 with my smart contract?how to solve truffle migrate erro?How do I convert the address returned from my smart contract into a readable string?

Can a Time Lord survive with just one heart?

Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?

What do you call the angle of the direction of an airplane?

How to supply water to a coastal desert town with no rain and no freshwater aquifers?

In the Seventh Seal why does Death let the chess game happen?

Bypass with wrong cvv of debit card and getting OTP

Should I warn my boss I might take sick leave?

Do intermediate subdomains need to exist?

What is exact meaning of “ich wäre gern”?

Why does mean tend be more stable in different samples than median?

How important is it for multiple POVs to run chronologically?

Do I need to be legally qualified to install a Hive smart thermostat?

Boss furious on bad appraisal

PhD: When to quit and move on?

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Does 5e have an equivalent of the Psychic Paper from Doctor Who?

Why do most airliners have underwing engines, while business jets have rear-mounted engines?

Who is responsible for exterminating cockroaches in house - tenant or landlord?

Why weren't Gemini capsules given names?

Why do Martians have to wear space helmets?

Red and White Squares

Sleepy tired vs physically tired

Is it possible to spoof an IP address to an exact number?

What can a novel do that film and TV cannot?



How to return array of address in solidity?


Solidity - Filling and using array of arrayError: Method eth_compileSolidity not supportedWeb3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of structupgradable smart contracts with Solidity: interface vs library?Expected Primary Expression (Solidity)browser/ballot.sol:102:18: ParserError: Expected '{' but got identifier contract token is ERC20Interface, Owned, SafeMath { ^----^Function error with my Solidity map(int,string) while using javascript to return values to html.Can I use my custom ERC-20 with my smart contract?how to solve truffle migrate erro?How do I convert the address returned from my smart contract into a readable string?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am creating a smart contract in solidity ^0.5.1 in which I am getting Error.



Gives Error.



data location must be a memory for the return parameter in the function, but none was given.



In the below function I am getting error.



function getCitizen()public returns(address[])
return citizenArray;



the smart contract that I have tried so far.



 pragma solidity ^0.5.1;


contract Citizen



struct Citizens

uint age;
string fName;
string lName;



mapping(address => Citizens) citizenMap;

address [] citizenArray;

function setCitizen(address _address,uint _age,string memory _fName,string memory _lName) public

//creating the object of the structure in solidity
Citizens storage citizen=citizenMap[_address];


citizen.age=_age;
citizen.fName=_fName;
citizen.lName=_lName;

citizenArray.push(_address) -1;



function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



function getCitizenAddress()public returns(address[])
return citizenArray;





thanks in advance for the help.










share|improve this question






























    0















    I am creating a smart contract in solidity ^0.5.1 in which I am getting Error.



    Gives Error.



    data location must be a memory for the return parameter in the function, but none was given.



    In the below function I am getting error.



    function getCitizen()public returns(address[])
    return citizenArray;



    the smart contract that I have tried so far.



     pragma solidity ^0.5.1;


    contract Citizen



    struct Citizens

    uint age;
    string fName;
    string lName;



    mapping(address => Citizens) citizenMap;

    address [] citizenArray;

    function setCitizen(address _address,uint _age,string memory _fName,string memory _lName) public

    //creating the object of the structure in solidity
    Citizens storage citizen=citizenMap[_address];


    citizen.age=_age;
    citizen.fName=_fName;
    citizen.lName=_lName;

    citizenArray.push(_address) -1;



    function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
    return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



    function getCitizenAddress()public returns(address[])
    return citizenArray;





    thanks in advance for the help.










    share|improve this question


























      0












      0








      0








      I am creating a smart contract in solidity ^0.5.1 in which I am getting Error.



      Gives Error.



      data location must be a memory for the return parameter in the function, but none was given.



      In the below function I am getting error.



      function getCitizen()public returns(address[])
      return citizenArray;



      the smart contract that I have tried so far.



       pragma solidity ^0.5.1;


      contract Citizen



      struct Citizens

      uint age;
      string fName;
      string lName;



      mapping(address => Citizens) citizenMap;

      address [] citizenArray;

      function setCitizen(address _address,uint _age,string memory _fName,string memory _lName) public

      //creating the object of the structure in solidity
      Citizens storage citizen=citizenMap[_address];


      citizen.age=_age;
      citizen.fName=_fName;
      citizen.lName=_lName;

      citizenArray.push(_address) -1;



      function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
      return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



      function getCitizenAddress()public returns(address[])
      return citizenArray;





      thanks in advance for the help.










      share|improve this question
















      I am creating a smart contract in solidity ^0.5.1 in which I am getting Error.



      Gives Error.



      data location must be a memory for the return parameter in the function, but none was given.



      In the below function I am getting error.



      function getCitizen()public returns(address[])
      return citizenArray;



      the smart contract that I have tried so far.



       pragma solidity ^0.5.1;


      contract Citizen



      struct Citizens

      uint age;
      string fName;
      string lName;



      mapping(address => Citizens) citizenMap;

      address [] citizenArray;

      function setCitizen(address _address,uint _age,string memory _fName,string memory _lName) public

      //creating the object of the structure in solidity
      Citizens storage citizen=citizenMap[_address];


      citizen.age=_age;
      citizen.fName=_fName;
      citizen.lName=_lName;

      citizenArray.push(_address) -1;



      function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
      return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



      function getCitizenAddress()public returns(address[])
      return citizenArray;





      thanks in advance for the help.







      solidity smartcontracts






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 31 at 12:11







      harsh

















      asked Mar 25 at 19:23









      harshharsh

      7110 bronze badges




      7110 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          It make sense, as you are returning the storage array of address you cannot return it as it is, because it will try to return the actual address of citizenArray in the contract storage. You can send the array by making it in memory. Like this.



          function getCitizenAddress()public view returns( address [] memory)
          return citizenArray;



          Once you put it as memory, you will get the warning for this which will state that as you are not changing any state in the function, you should mark it view, I already did that in the above code.



          Lastly, when you resolved this error, you will get another error in this function:



          function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



          This error is because you mark this function as pure. There is a little but very important difference between pure and view.




          • view means you cannot change the state of the contract in that function.


          • pure means you cannot change the state in the function and not even can read the state or storage variables.

          In the above function of getCitizen you are actually doing read operations in your return statement. You can fix this by just putting view instead of pure. Like So:



          function getCitizen(address _address) public view returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);




          I hope it will resolve all your issues. Thanks






          share|improve this answer























          • thanks for answer.It works.

            – harsh
            Mar 26 at 8:42










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345063%2fhow-to-return-array-of-address-in-solidity%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          It make sense, as you are returning the storage array of address you cannot return it as it is, because it will try to return the actual address of citizenArray in the contract storage. You can send the array by making it in memory. Like this.



          function getCitizenAddress()public view returns( address [] memory)
          return citizenArray;



          Once you put it as memory, you will get the warning for this which will state that as you are not changing any state in the function, you should mark it view, I already did that in the above code.



          Lastly, when you resolved this error, you will get another error in this function:



          function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



          This error is because you mark this function as pure. There is a little but very important difference between pure and view.




          • view means you cannot change the state of the contract in that function.


          • pure means you cannot change the state in the function and not even can read the state or storage variables.

          In the above function of getCitizen you are actually doing read operations in your return statement. You can fix this by just putting view instead of pure. Like So:



          function getCitizen(address _address) public view returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);




          I hope it will resolve all your issues. Thanks






          share|improve this answer























          • thanks for answer.It works.

            – harsh
            Mar 26 at 8:42















          0














          It make sense, as you are returning the storage array of address you cannot return it as it is, because it will try to return the actual address of citizenArray in the contract storage. You can send the array by making it in memory. Like this.



          function getCitizenAddress()public view returns( address [] memory)
          return citizenArray;



          Once you put it as memory, you will get the warning for this which will state that as you are not changing any state in the function, you should mark it view, I already did that in the above code.



          Lastly, when you resolved this error, you will get another error in this function:



          function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



          This error is because you mark this function as pure. There is a little but very important difference between pure and view.




          • view means you cannot change the state of the contract in that function.


          • pure means you cannot change the state in the function and not even can read the state or storage variables.

          In the above function of getCitizen you are actually doing read operations in your return statement. You can fix this by just putting view instead of pure. Like So:



          function getCitizen(address _address) public view returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);




          I hope it will resolve all your issues. Thanks






          share|improve this answer























          • thanks for answer.It works.

            – harsh
            Mar 26 at 8:42













          0












          0








          0







          It make sense, as you are returning the storage array of address you cannot return it as it is, because it will try to return the actual address of citizenArray in the contract storage. You can send the array by making it in memory. Like this.



          function getCitizenAddress()public view returns( address [] memory)
          return citizenArray;



          Once you put it as memory, you will get the warning for this which will state that as you are not changing any state in the function, you should mark it view, I already did that in the above code.



          Lastly, when you resolved this error, you will get another error in this function:



          function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



          This error is because you mark this function as pure. There is a little but very important difference between pure and view.




          • view means you cannot change the state of the contract in that function.


          • pure means you cannot change the state in the function and not even can read the state or storage variables.

          In the above function of getCitizen you are actually doing read operations in your return statement. You can fix this by just putting view instead of pure. Like So:



          function getCitizen(address _address) public view returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);




          I hope it will resolve all your issues. Thanks






          share|improve this answer













          It make sense, as you are returning the storage array of address you cannot return it as it is, because it will try to return the actual address of citizenArray in the contract storage. You can send the array by making it in memory. Like this.



          function getCitizenAddress()public view returns( address [] memory)
          return citizenArray;



          Once you put it as memory, you will get the warning for this which will state that as you are not changing any state in the function, you should mark it view, I already did that in the above code.



          Lastly, when you resolved this error, you will get another error in this function:



          function getCitizen(address _address) public pure returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);



          This error is because you mark this function as pure. There is a little but very important difference between pure and view.




          • view means you cannot change the state of the contract in that function.


          • pure means you cannot change the state in the function and not even can read the state or storage variables.

          In the above function of getCitizen you are actually doing read operations in your return statement. You can fix this by just putting view instead of pure. Like So:



          function getCitizen(address _address) public view returns(uint,string memory ,string memory )
          return(citizenMap[_address].age,citizenMap[_address].fName,citizenMap[_address].lName);




          I hope it will resolve all your issues. Thanks







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 0:55









          Abdullah AzizAbdullah Aziz

          2081 silver badge7 bronze badges




          2081 silver badge7 bronze badges












          • thanks for answer.It works.

            – harsh
            Mar 26 at 8:42

















          • thanks for answer.It works.

            – harsh
            Mar 26 at 8:42
















          thanks for answer.It works.

          – harsh
          Mar 26 at 8:42





          thanks for answer.It works.

          – harsh
          Mar 26 at 8:42








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345063%2fhow-to-return-array-of-address-in-solidity%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript