Search code examples
blockchainethereumsolidity

Access multiple return values (a, b, c) from solidity function in web3js


I have a function that returns multiple values. I wish to access these from Web3js.

function testReturnBet(uint index) constant returns (address player, 
                                                     uint tokensPlaced, 
                                                     uint8[4] numbers,
                                                     uint ratioIndex,
                                                     uint timestamp,
                                                     uint rollIndex,
                                                     uint winAmount) {
        bet outBet = bets[index];
        return (outBet.player,
                outBet.tokensPlaced, 
                outBet.numbers, 
                outBet.ratioIndex, 
                outBet.timestamp, 
                outBet.rollIndex, 
                outBet.winAmount);
    }

Solution

  • You'll get an array of return values with 7 values (0-6). The third one should be an array with 4 values.

    In the Truffle style, it would look something like:

    contract.testReturnBet(index).then(function(response) {
      console.log(response); // should be an array
    });