I have been reading about Solidity release version 0.4.17.
https://github.com/ethereum/solidity/releases
One of the following statements was really interesting:
We also worked further on the new ABI encoder: Functions can now
return structs. Switch it on using pragma experimental ABIEncoderV2.
It should already work, but still generates more expensive code.
I`ve been trying to simulate that in Remix but without any luck, I am getting this error:
"error": "Failed to decode output: Error: Unsupported or invalid type:
tuple"
Here is my code:
pragma solidity ^0.4.17;
pragma experimental ABIEncoderV2;
contract StructTest{
struct someTestStruct {
uint A;
uint B;
bytes32 C;
}
someTestStruct str;
function StructTest(){
str = someTestStruct({A: 5, B: 6, C: "Hi"});
}
// trying to get struct but getting "error": "Failed to decode output: Error: Unsupported or invalid type: tuple"
function returnStruct() returns (someTestStruct){
return str;
}
}
Have someone tried this? What am I doing wrong here? Thanks in advance!
Best Answer
Yes we can return structs.
But only in internal function calls.