I have the following Solidity code:
uint public roundNumber;
struct Lottery {
uint256 ticketsSold;
uint256 winningTicket;
}
mapping (uint => Lottery) public lotteries;
And want to call for example lotteries[roundNumber].ticketsSold
in Web3.
I have the following javascript code (using Web3):
var roundNumber;
contractInstance.roundNumber.call().then(function (result) {
roundNumber = Number(result);
console.log(result + ' is the result'); // returns "0 is the result"
})
contractInstance.lotteries.call(roundNumber).then(function (result) {
console.log(result[0].toString()); // tickets sold
console.log(result[1].toString()); // winning ticket
})
This results in the following error:
new BigNumber() not a number: [object Object]
If instead of contractInstance.lotteries.call(roundNumber)
above I just do contractInstance.lotteries.call(0)
there's no error, so there's an issue with the roundNumber
variable (even though I've verified it is 0
and is of type Number).