[Ethereum] Contract reading a string returned by another contract


I have 2 contracts, Parents and Child which has a public string variable – name.

contract Child {
    string public name;
    function child (string _name){
       name = _name;

Parents needs to get that name:

contract Parents {
    string public childName;
    Child child;
    function Parents(address _childAddress){
        child = Child(_childAddress);
        childName = child.name();  // I also tried child.name

But I'm getting the following error:

Error: Type tuple() is not implicitly convertible to expected type string storage ref.
        childName = child.name();

So I've tried to create another function in Child that will return a string:

function getName() returns (string name) {
    return name;

And in Parents I've changed

childName = child.name();  into--->  childName = child.getName();

But I keep getting the same error. Any ideas?
As always, your help is appreciated.

Best Answer

Variable-sized data that is returned by one contract, cannot be read by another contract.

Parents is trying to read a string from Child and thus the error.


The EVM is unable to read variably-sized data from external function calls... Note that on the other hand, it is possible to return variably-sized data, it just cannot be read from within the EVM.

EIP 5 is a proposed update of the EVM that's needed to allow contracts to read dynamically-sized data returned by other contracts.