You can not return a struct
because Solidity implements them only as a loose bag of variables, they are not real objects.
You can use a solution from this answer: https://ethereum.stackexchange.com/a/3614/264
Update
Since 0.4.17
you can use pragma experimental ABIEncoderV2
to return structs. Of course, until the experimental
keyword is removed, it's not safe to use it in production apps.
In practice, the call stack imposes a limitation in current implementations.
The following contract will face a 'Stack too deep' compiler error.
pragma solidity ^0.4.3;
contract Test {
function getData() constant returns (bytes32, bytes32, bytes32, bytes32,
bytes32, bytes32, bytes32, bytes32,
bytes32, bytes32, bytes32, bytes32,
bytes32, bytes32, bytes32) {
return ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o");
}
}
Browser Solidity:
https://ethereum.github.io/browser-solidity/#gist=ac9812a045a41fd4168f2e352732962d
Gist URL:
https://gist.github.com/anonymous/ac9812a045a41fd4168f2e352732962d
Best Answer
There are a few types of string values that you may be referring to.
bytes1
-bytes32
: fixed size.bytes
orstring
: dynamically sized.Solidity supports functions with multiple return values.
You can do the same with
bytes
orstring
but with the limitation that solidity does not support returning dynamically sized values to other functions. This means that you would be able to use thegetData
function from within another contract and retrieve the return values but you would not be able to retrieve the return values fromgetDynamicData
from within a contract.You can however retrieve the return values from both
getData
andgetDynamicData
whencall
from outside of the blockchain.