Hi Dani,
thank you very much for the reply and the resources. I have read through them and the web3 documentation link is what I was looking into several times.
Still it seems not to be working for me as expected the following code from my main.js:
contractInstance.events.queryResultReceived({filter: {player: userAccount}, fromBlock:0}, function(error, event){console.log(event)});
Results in the following message in the developer console:
Uncaught TypeError: Cannot read property 'events' of undefined
at main.js:48
This message does appear what ever I have tried it seems I am missing something very basic.
The initialization of the contract in my code is pretty close to what you have written in your FAQ
This is the solidity code from the contract for the event:
Definition:
event queryResultRecieved(
address indexed player,
uint won,
uint randomNumber,
uint headstails
);
Emition in _callback of provable:
emit queryResultRecieved(bets[_queryId].creator, won, randomNumber, bets[_queryId].headstails);
Sofar I was able to resolve all the issues I ran into by searching on the net an trying but this one is giving me troubles and it looks like I am missing something very basic.
Just in case my main.js code without the functions I call (left the comented event listeners in which I tested; also tried to put the event code at several location in the main.js to test):
var web3 = new Web3(Web3.givenProvider);
var contractInstance;
var contractAddress = "0xb69561B73f386D17B583Ec41c134A8a928169e14";
var coinSelection = "99";
var userAccount = "Not Connected";
$(document).ready(function() {
window.ethereum.enable().then(function(accounts){
contractInstance = new web3.eth.Contract(abi, contractAddress, {from: accounts[0]});
userAccount = accounts[0];
console.log(contractInstance);
$("#playerAdress").text(userAccount);
});
contractInstance.event.queryResultReceived({filter: {player: userAccount}, fromBlock:0}, function(error, event){console.log(event)});
/*
contractInstance.event.queryResultRecieved({
filter:{userAccount}
).on('data', function(event){
var data = event.returnValues;
console.log(data); // same results as the optional callback above
}).on('error', console.error);*/
/*contractInstance.queryResultRecieved({filter:{player: userAccount}
}).watch(function(error, result){
if (!error){
console.log(data);
console.log("Player " + result.player);
console.log("Won " + result.won);
console.log("Random Number " + result.randomNumber);
console.log("Heads or Tails " + result.headstails);
}
});*/
$("#flip_coin").click(flipCoin);
$("#deposite").click(contractDeposite);
$("#withdrawPartial").click(withdrawPartial);
$("#withdrawAll").click(withdrawAll);
$("#refresh").click(jackpotBalance);
$("#getPlayer").click(lastResult);
$("#initPayout").click(initiatePayout);
$("#queryCheck").click(checkForQuery);
$("#coin_heads").click(selectHeads);
$("#coin_tails").click(selectTails);
$("#players").click(getNumberOfPlayers);
});
Thank you,
Ralf