Solidity Function Limits – Is There a Limitation on Number of Return Values?

contract-deploymentcontract-developmentcontract-invocationgo-ethereumsolidity

Answer of this question (https://ethereum.stackexchange.com/a/3590/4575) says that: "I am not allowed to return dynamic arrays from Solidity functions yet."

On the other hand, Solidity supports functions with multiple return values. How can I return multiple strings from a contract function?

[Q] Is there any limitation for the number of the return values in one function call. Such as, could I return N (for example N=1000) number of values or even more in one function call?

function getData() constant returns (bytes32, bytes32, bytes32, bytes32, 
                                     bytes32, bytes32, bytes32, ...) {
    bytes32 a = "a";
    bytes32 b = "b";
    bytes32 c = "c";
    bytes32 d = "d";
    bytes32 e = "e";
    bytes32 f = "f";
    bytes32 g = "g";
    return (a, b, c, d, e, f, g, ...);
}

Thank you for your valuable time and help.

Best Answer

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

Related Topic