Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (4.1k points)

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);
    }

1 Answer

0 votes
by (14.4k points)

You'll get an array of return values with 7 values (0-6). The third one should be an array with 4 values. Thus you will be able to return multiple values from Solidity function in web3js.  

In the Truffle style:

contract.testReturnBet(index).then(function(response) {

  console.log(response); // should be an array

});

Browse Categories

...