Multiple return values from a function

crayons610crayons610 Member Posts: 11
I could get a solidity function like:
foo() returns(uint bar, uint baz) {}
to compile, but I couldn't figure out how to access the return values when the function is called.
Are multiple return values legal & how to access them pls?


  • lefterislefteris Member Posts: 7
    Multiple returns values are not yet implemented. The syntax for declaration of a function with multiple return values is there but that's all for now. It's a pending TODO item.
  • chrisethchriseth Member Posts: 170 ✭✭✭
    The return values should be "sent to the wire", though, i.e. they should be part of the "return value" if it is a message call.
  • crayons610crayons610 Member Posts: 11
    I found multiple returns by accident, I think a leftover from a prior serpent attempt.
    Will be a nice feature though.

  • chrisethchriseth Member Posts: 170 ✭✭✭
    By the way, the plan is to allow something like this in Solidity:
    (a, b, c) = f();
  • oomooomo Member Posts: 31
    Do we know if multi-value return supported now in Solidity? Due to the lack of support of returning struct, this will be extremely helpful. Currently, we end up defining getter() per field in struct. This multiple return could be pushed out to JSONRPC returning an JSON.
  • chrisethchriseth Member Posts: 170 ✭✭✭
    edited June 2015
    Note that returning multiple values was supported from the start. The only thing that is not supported is accessing more than one returned value after a call to another contract. This here works:
    contract c {
    struct s { uint a; uint b; string d; }
    s data;
    function f() returns (uint a, uint b, string d) {
    a = data.a;
    b = data.b;
    d = data.d;
    Post edited by StephanTual on
  • oomooomo Member Posts: 31
    @chriseth First, can you please elaborate on "accessing more than one returned value after a call to another contract"? Secondly, can you show on example in JavaScript on how would I fetch this multiple values? I read somewhere that it is returned as an array? It would have been nice if this was returned as a JSON
  • chrisethchriseth Member Posts: 170 ✭✭✭
    edited June 2015
    On "accessing more than one returned value": Given the above contract, in the following code, x will be of type uint and only contain the "a"-part of the return values of f.
    contract c2 {
      c otherContract;
      function g() {
        var x = otherContract.f();
  • jwgcarlylejwgcarlyle Member Posts: 29
    Is there any progress on the capability
    (a, b, c) = f();
    that was outlined earlier? In my use-case, I want to have an internal function that can return a couple of values to a calling code block, so the comments above about a call to another contract don't apply.

    I'd be happy to keep track of the backlogged item, if it's easier to post a link.
  • chrisethchriseth Member Posts: 170 ✭✭✭
    It is now possible to return a struct from an internal function, so that can be used as a work-around for now.

    The story is here:
Sign In or Register to comment.