Hey everyone. I have a gaming related question that is slightly off topic for the project but not for an upgrade. What are deposit bonuses and extra rolls and how do they work? Seems self evident but I have not found a good explanation. Thanks!
thankâs gabba .
I also had some problems with python -m http.server . it wasnât updated but itâs ok now.
Hi Filip and everyone. Begginers questions:
- in the course lecture there was supposed to be a link for âhow to listen to an eventâ. i think it is missing.
2.I am trying to change a mapping variable called âawaitâ from true to false after the call was received. Is it because that in order to do so i need also to catch the event? . see below:
mapping (address => bool) public await;
function __callback (bytes32 _queryId, string memory _result, bytes memory _proof) public {
require (msg.sender== provable_cbAddress());
await [msg.sender] = false;
uint256 randomNumber = uint256(keccak256(abi.encodePacked(_result))) % 2; //was 100 originally
latestNumber [playerAddress] = randomNumber;
emit generatedRandomNumber (latestNumber [playerAddress]);
}
function update() private {
uint256 QUERY_EXECUTIO
`Preformatted text`N_DELAY = 0;
uint256 GAS_FOR_CALLBACK = 200000;
require (await[msg.sender]== false);
bytes32 queryId = provable_newRandomDSQuery (QUERY_EXECUTION_DELAY, NUM_RANDOM_BYTES_REQUESTED, GAS_FOR_CALLBACK);
senderQueriId[msg.sender]= queryId;
await[msg.sender]=true;
emit LogNewProvableQuery ("provable was sent, standing by for answer..");
}
Hi @gabba @filip, itâs been a while, everybody is on lockdown now and I found myself trying to complete the ETH 201 course. Iâm having troubles with listening to events from the oracle, it doesnât work, the getPastEvents function for my Solidity event returns an empty list, could you please help me?
Here is the source code
Really nice challenge!
Ok, Iâve pushed the code to a another branch: https://github.com/PedroMD/eth201-coinflip/tree/phase2-oracle
I have one question, though⌠Here:
// FIXME. not filterning by queryId...
contractInstance.once('userWon', {
filter: {
queryId: queryId
},
fromBlock: 0,
toBlock: 'latest'
}, function (error, event) {
It seems that the event is not really filtering by the queryId
⌠If I open another window and play the same game concurrently (2 plays from the same account in a matter of 1 second), one of these windows will get the other event regardless, because they are not filtering by the corresponding queryId
.
Any idea?!
Thanks!
Hey there, happy to help
- Sorry about that. Iâve added it now. Here you can see how you do it in web3.js documentation: https://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#id36
Here you can see a rough implementation of it as well: https://ethereum.stackexchange.com/questions/35997/how-to-listen-to-events-using-web3-v1-0
- Iâm not sure that I totally understand you question here. But yes, thatâs good. You want to limit the player to only have one game going at the same time. Allowing a player to have 10s or 100s of pending games at the same time might be dangerous for your contract. So we limit the player by using a mapping like you have done. Are you having any issues with the code currently?
Good job dude! I checked your code and I found one error. Iâm proud to see that you tested the code and found the error. Now, how do we fix it.
It has to do with whatâs called indexed event parameters. You can specify when you define the event in your contract if some of the parameters should be indexed or not. Indexed means that they can be filtered on. So if you want to be able to filter on queryId, you need to put queryId as an indexed parameter when you define the event.
event userWon(bytes32 indexed queryId, address player, uint256 prize, bool won);
Good job! I think you should be looking at @PedroDiogo code that was posted right below for how to listen for events. You want to use the once() function. GetPastEvents only retrieves already old events I think.
Try the code that pedro posted above
@filip , thank you very much! Really missed that bit when reading the docs. Got it now, so simple
Will add this and also adopt structures, not just mapping (more elegant solution).
Looking forward for the security course!
Hi Filip
yes, the problem is that the value of the âawait[msg.sender]â in the callback function is not changing back to falseâŚ
Thanks for helping
Hi @filip @PedroDiogo, I thought that the mistake was in the way I wrote my solidity contract or my main.js file, so I tried using @PedroDiogoâs, but I still donât get any events. What else could I be missing out? The link to the github project: https://github.com/dominikclemente/coinflip-dapp
Hi @Guy
Your _callback function should be called by the provable api, you donât need to catch the event to make it works.
You will have to catch the event generatedRandomNumber
to get your result. If you are not seeing your âawaitâ variable set to false, their is 2 options:
- Their is an issue with the provable api, check in etherscan at your address if you see an external interaction with your smart contract ?
- Your function is reverting in the require , did you set
provable_setProof(proofType_Ledger);
in your constructor ?
Can you send the transaction hash of one of your failing transaction ?
Hi @Dominik_Clemente
I donât see the indexed key word in your event
event userWon(bytes32 queryId, address player, uint256 prize, bool won);
Should be
event userWon(bytes32 indexed queryId, address player, uint256 prize, bool won);
Are you using ganache gui ? I had issues with ganache gui mine doesnât send back events.
I make it works with ganache-cli you can install it with npm.
I lok at your code which seem correct.
Do you need Ganache to interact with the smart contract if it is deployed on the ropsten test network? Donât you only need Truffle?
Ho you also have the error when itâs deployed, i though it was just locally, i ll clone your code and test it
Thanks, I tried locally and it worked with the local development trick showcased by @filip. Ohhh, I was missing the --reset argument. I only recompiled, not redeployed, didnât I?
Congratulations on finishing the projectâŚ
Ivo
Thank you! Next is Defi 101 and then smartcontract security.
Hello,
I had this same issue and was able to downgrade my node version and resolve infura connection error
I am trying to test out the random number generation code on the ropsten network, but Iâm getting the following error even though I have deployed the contract. Please let me know your thoughts on this
Thank you,