Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

solidity

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;
    }

}
like image 671
Dap Avatar asked Jul 09 '17 00:07

Dap


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.

like image 197
Rishi Gulati Avatar answered Oct 09 '22 00:10

Rishi Gulati