2

First just have a look at my easy code so that I can explain by giving references.

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract GeoSpatialData{
    
    struct GeoData{
        uint id;
        address owner_address;
        string data_name;
        string data_year;
        string data_description;
        string data_img_url;
        string data_url;
        string data_category;
        string data_published_date;
    }
    GeoData[] public geoData;
    // write function
    function createData(string memory _data_name,address _owner_address,string _data_year,string _data_description,string _data_image_url,string _data_url,string _data_published_date ) public{
           
    }

    // read all data  function
    function readData() public{

    }

    // read single data function 
    function readSingle() public{

    }    
}

Now I have a struct of GeoData as you can see. What I want is to create an object of this so definitely I am going to need the parameters while passing them in the create data. I am getting the error that Data location must be "memory" or "calldata" for parameter in function, but none was given.

I learned the way to create objects from this course. Here is the link of the github whose code inspired me to write code like this.

I also have one more question: Is storing all the data in an array a good idea? Can't I store as class objects? Does solidity support these programming concepts?

2 Answers 2

5

You have to set data location type to function parameters & returns to establish where the data would be during the life time of the function you would be calling. "memory" & "calldata" & "storage", would establish where the function parameter data would be store and where the data is placed so the function return can return these data.

Watch these videos and example code to understand better :>

2

This post does a very good job explaining Solidity storage locations:

https://medium.com/coinmonks/solidity-storage-vs-memory-vs-calldata-8c7e8c38bce

1
  • Link only answers are discouraged. It is better to include the more important details in the answer and use the link to expand other details.
    – Ismael
    Mar 2, 2023 at 4:34

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.