3

This is the function. I am very new to this. Can someone please tell me what is wrong in this.

function getData(string Key) constant returns (string[], string[]) {

    uint length = data.length;

    string[] memory key = new string[](length);
    string[] memory hash = new string[](length);

    for(uint i=0; i < data.length; i++ ) {
        Data memory currentData;
        currentData = data[i];

        key[i] = currentData.key;
        hash[i] = currentData.hash;
    }

    return (key,hash);
}
1
  • Can you update the question with the complete code? What's data in this function is not defined. – Sanchit Jul 5 '17 at 4:31
2

It's complaining about returns(string[]).

You're trying to return variable length arrays but the interface is limited to 16 fixed length arguments or 8 strings, with a further caveat about strings - they can't be passed between contracts.

These are limitations of the current compiler.

This code replicates the same error:

pragma solidity ^0.4.6;

contract TestContract{

    function test() constant returns(string[], string[]) {
        // ^ no good
    }

}

If you need a workaround for large arrays, you can call return vals by row number. Something like:

function x(uint row) constant returns(string) {
  return myString[row][
}

Or even:

string[] public myString; 

By declaring it public, you get a "free" getter function that does the same thing. For completeness, I should say that public has additional implications if any contracts inherit the code.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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