Hey @Ula
I am running your code and seems working for me, please DM me with your wallet address, I need to do some verifications.
Cheers,
Dani
Hey @Ula
I am running your code and seems working for me, please DM me with your wallet address, I need to do some verifications.
Cheers,
Dani
hey Erno, loving the project! just stumbled across and liking you using all the cool things react has to offer UX is pretty cool too
Hi @cryptocrom, thank you for all of your advices, it really helped:) error in console stopped showing up and I think I havenāt had anything to do with that
var query_Id;
contractInstance.events.LogQueryId
function(error, event){console.log(event);})
.on('data', function(event){
query_Id = event.returnValues.queryId;
});
this part definitely worked for me, also there was no need to put event listeners on the top, but seems like they donāt work when placed in the called method, does anyone know why?
contractInstance.methods.flip(coinside).send(config)
.on("transactionHash", function(hash){
console.log(hash);
$("#action").text("Wait for your transaction to be confirmed");
})
.on("confirmation", function(confirmationNr){
$("#action").text("Transaction confirmed! Wait for result of your game");
console.log("transaction confirmed"); // no event listener will work here
My thinking was that LogQueryId event listener placed in the flip() function in js will be āattachedā to this particular user who called this fuction, am I wrong? I also tried to place it inside .on("receipt", function(receipt){...}
option, but it doesnt show up in the consoleā¦Is it better to filter by user address?
Here is my main.js file for better picture:
var web3 = new Web3(Web3.givenProvider);
var contractInstance;
$(document).ready(function() {
window.ethereum.enable().then(function(accounts){
contractInstance = new web3.eth.Contract(abi, "0x3bFA3EA63836bfaB3dd24fA07d8CBf6A912AbA55", {from: accounts[0]});
console.log(contractInstance);
});
$("#flip").click(flipAcoin);
$("#withdraw").click(withdraw);
$("#showbalance").click(balance);
$("#withdrawbalance").click(withdrawbalance);
});
function flipAcoin(){
var coinside = $("input[name=coinside]:checked").val();
var betvalue = $("#bet_input").val();
var config = {
value: Web3.utils.toWei(betvalue, "ether")
}
var query_Id;
console.log("the coinside is " + coinside);
console.log("the bet amount is " + betvalue);
if (betvalue<0.1) alert("minimum bet is 0.1 ether");
contractInstance.methods.flip(coinside).send(config)
.on("transactionHash", function(hash){
console.log(hash);
$("#action").text("Wait for your transaction to be confirmed");
})
.on("confirmation", function(confirmationNr){
if (confirmationNr == 0) {
$("#action").text("Transaction confirmed! Wait for result of your game");
};
console.log("transaction confirmed");
})
.on("receipt", function(receipt){
receipt.events.LogQueryId(function(error, result){
query_Id = result.returnValues.queryId;
console.log(query_Id);//this event doesn't work, any ideas
//why events inside the method dont work?
})
})
contractInstance.once('coinFlipResult'
, {filter: {queryId: query_Id}
, fromBlock: 0
, toBlock: 'latest'
}, function(error, event){
console.log(event);
if (event.returnValues.win == true) {
let prize = web3.utils.fromWei(event.returnValues.prize, "ether")
$("#action").text("Congratulations! You won! Your prize is: " + prize);
}
else {
$("#action").text("Ahhh... You lost a bet");
}
})
}
Awesome, thanks for the feedback and glad at least some of it helped - I just hope I am not like the blind leading the blind hahaā¦
I have no idea why my event listeners only work at the top then - so frustrating.
Anyways, my understanding of event listeners is that they subscribe to a particular event of the contract you set them to listen for and any event that matches the criteria (the filters, if you set any) will show up as requested.
Sending a transaction to your contract is a separate instance to an event firing - even if the event emitter is within the function of that transaction in your smart contract - they are separate occurrences, so Iām guessing this is partly to do with why it doesnāt work and also because I believe they are asynchronous, the function would just listen - hear nothing and move onā¦but if you have the event listener on its own, it will be always listening and can carry out whatever instructions it has when ever the event criteria are met.
Youāre not really wrong but the front end doesnāt really care who the user is unless you tell it directly - looking bigger picture, you would probably run into trouble if lets say 5 people are playing your DApp all at the same time. During testing with a single user and bet, you will not have any issues, but lets say you do have 5 people playing and they all put their transaction in at nearly the same time. They will all be using the same front end code, each person will have slightly different variables based on their bet but when it comes to the waiting for results, they will all be waiting for the event LogQueryId to fire. So while you are correct that the LogQueryId event listener is attached to them in the smart contract, the front end canāt tell the difference between users and this is where you could run into trouble. You have to tell it what to look for, for example filtering for the queryId or the user address in the event listener so that it only picks up on events that are pertinent to that user or their callback id and then fires the code included accordingly. Otherwise you and I might both be waiting for results and then when your results come in, my front end may fire and tell me that Iāve won, when in fact the smart contract is telling a different story. I know that most of us probably arenāt going to deploy this as a DApp for real use, but I think it is useful pretending that you will and then trying to address any issues that you think might pop up during use on a larger scale. This has helped my understanding greatly as it helps me to think about issues I might have later, not just addressing issues I have as I go. Anyways, thanks heaps for the feedback - I thought Iād given you rubbish advice after Dani said she had it all working for her. Glad youāre having some luck with it - good luck.
Hey guys, when I try to deploy my contract to the Ropsten network, I get this error below:
Anyone familiar with this?
what was the other faucet urls? I get this on error on faucet.metamask.io:
{āerrorā:"[ethjs-query] while formatting outputs from RPC ā{āvalueā:{ācodeā:-32000,āmessageā:āreplacement transaction underpricedā}}ā"}
Iāve got no clue at all but found a few github threads regarding this issue and it seems like maybe changing the gas price āmayā do the trickā¦a couple of the threads are listed below, all I did was copy and paste your error message into my search engine and have a readā¦
{ājsonrpcā:ā2.0ā,āidā:3,āerrorā:{ācodeā:-32000,āmessageā:ātransaction underpricedā}}
web3.eth.sendTransaction({ from: from, to: to, value: value, gasPrice: "20000000000", gas: "21000" }, function(error, result){ if(error) { } else { } })
{ājsonrpcā:ā2.0ā,āidā:3,āresultā:ā0xe47688ed9bc2b9d4f631b0a94b7a40dd83ab884ec1493e3ba9b741da67b3a83bā}
I found this post in this thread above - I have not used this but FrankB seems to have had success with it.
Good luck
answered in DM because the code was too long to be posted here.
Hey @eaglejr
Please downgrade your NODE JS by following this FAQ: FAQ - How to downgrade Node.Js
Keep me posted.
Dani
Hey @bjorkmanders
Those are most likely errors on their side. What you can do is reset Metamask but nothing more than that.
In these cases I suggest to try other faucets, and come back to that one later on.
Happy coding,
Dani
I think Iām on the cusp of being able to code the website now, but the main purpose of the contract isnāt working!
In the Coinflip_vOracle.sol file, the function flipCoin
returns the following error when tested on Remix:
transact to Coinflip_vOracle.flipCoin errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Debug the transaction to get more information.
Iām not really sure what the problem is, since it was working weeks ago, while the rest of the contract wasnāt ready.
Can anyone solve the problem? @dan-i
Another question: I deployed a previous version of the contract on Ropsten through Remixās Injected web3. How do I interact with this deployed version of the contract?
https://ropsten.etherscan.io/tx/0xb4f8c8ffc69248a7249de566a62e5940af6b3bf6902245ed8f483e0e270b9e19
I got stuck with the stupidest problem. My ganache is constantly lugging and shuts down when I try to deploy the Coinflip project with all of those ProvableAPI.sol contracts. Does anyone experience the same problem? Is there a way to minimize that contract?
@dan-i Ok so I changed the compiler version and it looks like it fixed the error I was getting, but now Iām facing a new error when I open the dapp in a browser.
It looks like itās referring to this line of code in the main.js file
Hey @eaglejr
@dani69654 Ok so I changed the compiler version and it looks like it fixed the error I was getting, but now Iām facing a new error when I open the dapp in a browser.
You get this error because you are not running a local server.
Remember to run python simple server and test you dapp in your localhost
python -m SimpleHTTPServer 8000
;localhost:8000
Happy learning,
Dani
The youtube video posted is private, therefore I cannot watch it.
Also if you are using ProvableApi means that you have to deploy in Ropsten and not in your local Ganache.
Keep me posted,
Dani
Iāve changed permissions.
As for ProvableApi, I am using it with that dummy contract proposed in the video to first develop a smartcontract instead of redeploying it each time I need to make changes.