5

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

I am using truffle for my development work. Believe this code can help you out. Just tried to list you out the basic structure. You need to replace the function parameters with actual ones and accordingly use the output parameters as well.

Hope this helps.

Sample Code Block

import { default as Web3} from 'web3';
import { default as contract } from 'truffle-contract'

import general_voting_artifacts from './../../build/contracts/MyContract.json'

var MyContract = contract(general_voting_artifacts);

 MyContract.deployed().then(function(contractInstance) {  
    contractInstance.testReturnBet.call(param1, param2,....paramn).then(function(v) {  
            var res1 =v[0].toString();  
            var res2 =v[1].toString();  
///         ....  
            var resn =v[n].toString();  
        });  
  });  
  • 1
    Ok so the result is just an array of those parameters. – RFV5s Mar 26 '17 at 16:03
  • yep, hope that answers your query – Susmit Mar 26 '17 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.