Why can't you pass strings from contract to contract?

Viewed 2725

When calling trying to pass a string from contract to contract, I get an error. in getName with error. I'm aware you cannot pass strings but what is the reason?

Return argument type inaccessible dynamic type is not implicitly convertible to expected type (type of first return variable) string memory. return toBeCalled.getName();

pragma solidity ^0.1.0;

contract ToContract{
    FromContract fromContract = new FromContract();

    function getName() constant returns (string) {
        return fromContract.getName();
    }

}

contract FromContract{
    string name = 'dapp';

    function getName() constant return(string){
        return name;
    }

}
1 Answers

In solidity a string "Hey" is internally stored as ["H","e","y"] which is a dynamic array. As of now it has no support to pass dynamic arrays. you can try to work around this by passing the string as a part of an object.

Related