0

This question already has an answer here:

I am using two contracts where one calls a function of the other:

contract con1 {
    bytes32[5] data;

    function con1(){
    }

    function addData(bytes32[5] a) { //fills the array
    }   

    function getData() public constant returns(bytes32[5]){  //retrieve array
        return (data);
    }
}

The next contract calls getData from the above contract after it has been filled using addData:

contract con2 {
    function con2(){
    }

    function try(address con1Contract){
        con1 b = con1(con1Contract);
        bytes32[5] y = b.getData();
    }
  ....
}

Since in Solidity we cannot pass dynamic sized arrays, I fixed the size of the array. However, I still get the following error:

TypeError: Type bytes32[5] memory is not implicitly convertible to expected type bytes32[5] storage pointer.
bytes32[5] y = b.getData();

What am I doing wrong?

Also, is there a more efficient way to do this?

marked as duplicate by Eli Drion, Achala Dissanayake, mirg, Ismael, norganna Apr 2 '18 at 6:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • My question is not a duplicate. The other question is trying to receive the return call in a dynamic size array. – Fawzy3881 Apr 1 '18 at 16:36
  • It is. The same issue is encountered and an answer is given in this post. – Eli Drion Apr 1 '18 at 16:40
0

Try to make your "y" array property of the contract

 contract con1 {
    bytes32[5] data;

    function con1(){
    }

    function addData(bytes32[5] a) { //fills the array
    }   

    function getData() public constant returns(bytes32[5]){  //retrieve array
        return (data);
    }
}

contract con2 {
    bytes32[5] y;
    function con2(){
    }

    function trys(address con1Contract){
        con1 b = con1(con1Contract);
         y = b.getData();
    }
}

It works for me.

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