0

I am very new in Solidity programming. I was practicing a code by myself and faced this problem. Everything seems okay from the example except when i try to compile, it is giving me this error in solidity "TypeError: Data location must be "storage", "memory" or "calldata" for variable, but none was given". can u guys please help me understand and also tell me how can i write this part more accurately? Thank you very much for taking time! the code is below!

    function issueCertificate(
    address _issuer, address _prover, string memory _status,
    uint meatBatchId, bytes memory signature) public returns (uint) {
        Entity memory issuer = entities[_issuer];
        require (issuer.mode == Mode.ISSUER);

        Entity memory prover = entities[_prover];
        require (prover.mode == Mode.PROVER);

        Status status = unmarshalStatus(_status);

        uint[] id = certificates.length;
        Certificate memory certificate = Certificate(id, issuer, prover, signature, status);

        certificateIds.push(certificateIds.length);
        certificates[certificateIds.length-1] = certificate;

        emit IssueCertificate(_issuer, _prover, certificateIds.length-1);

        return certificateIds.length-1;
    }

1 Answer 1

1

In your code you have at least two declarations without data location while it's required. Reference types require the data location notation, according to solidity document: "reference types comprise structs, arrays and mappings":

  1. Status status = unmarshalStatus(_status); should become: Status memory status = unmarshalStatus(_status);

  2. uint[] id = certificates.length; should become: uint[] memory id = certificates.length;

For the second one, I don't think you mean to use array because the length could be integer. So you may use uint id = certificates.length; depends on the logic of your contract.

Read more : Data location

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.