Can you( or someone) explain to me why you wrote the code like that?
let result = receipt.events.flipResult.returnValues.value === ‘1’ ? ‘Heads’ : ‘Tails’
Im trying to understand why this format is effective for what you wanted to accomplish.
Can you( or someone) explain to me why you wrote the code like that?
let result = receipt.events.flipResult.returnValues.value === ‘1’ ? ‘Heads’ : ‘Tails’
Im trying to understand why this format is effective for what you wanted to accomplish.
You could use .once
and add filters to your event listeners.
Docs: https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#once
An example made by myself: https://github.com/dani69654/CoinFlip/blob/master/client/main.js
Ok thanks a lot! I get it now
So im practically done with this phase but I’ve been consistently getting an out of gas error come up. What could possibly be the reason for this?
I’ve upped my gas amount while conducting the transaction and I sometimes still receive this error. Why am I out of gas only sometimes?
I also noticed that this happens most often when I make consecutive transactions.
Hey @KaiStryker
That could be an issue with your contract, can you please share your GitHub repo? I would love to take a look
Cheers,
Dani
Not a great UI but basically I have 2 views
1- for owner where he can Deposite, Withdraw and view Contract Balance as well as can Bet as normal user.
2 - Gambler he can place a bet with his choice and amount, his account balance gets updated as soon as the bet results are displayed.
Next step for me improve UI.
Hey @KaiStryker
I think the error is related to the require statement in your placeBet
function.
Add an error message and verify:
require (address(this).balance >= _balance, 'not enough balance to play');
Keep me posted,
Dani
Hey @dan-i,
I tried that but that didn’t seem to be the issue because it didn’t return my message. I took a deeper look at the error message and saw that the error message said something about the event emitter. Then it clicked to me that maybe the issue was that the gas was running out due to the emitter taking a significant amount each transaction.
So I decided to experiment with setting the gasPrice and the gasLimit in the instance and now the transactions are seamless . Thanks a lot for your help, this was a great learning experience on the importance of trial and error testing.
Here are some screenshots of the DApp in action; will work on the front end look once I learn ReactJs:
https://github.com/KaiStryker/coinflip-dapp/tree/main/dapp-screenshots/phase-one
Looking forward to phase 2!
Kai
See you in phase two
Well i took me a week or so, but i got the phase one up and running:
https://www.youtube.com/watch?v=gMZxLoDqF_M&feature=youtu.be
CoinFlip DAPP Demonstration
Winning
I solved the problem. i had issues with ganache UI. now since im only using ganache-cli it works.
Hello everyone! I’m finishing up the front end for Phase 1 and I keep getting this error:
web3.min.js:1 Uncaught Error: Please pass numbers as strings or BigNumber objects to avoid precision errors.
I’ve looked online and tried several different solutions but nothing seems to be working. Any help would be greatly appreciated! Thank you and cheers!
Hey @a.lwsn
Based on the error message Please pass numbers as strings or BigNumber
although you have not specified which function you are calling I think it is related to web3.
Pass the parameter as string should fix
Instead of function(1)
do function("1")
For further request please specify the function you’re calling and post the code so that I can be more specific.
Regards,
Dani
I finished part one of the Coin Flip Dapp, as seen above. However I wasn’t able to get it to work the way I wanted it to as per my original thinking.
I wanted everything to complete with only one button click. Everything seemed to work in the Solidity code I wrote, I checked it in Remix, it all seemed fine.
But when I deployed it in Truffle, I could not get the final message, that states whether the bettor won or lost, to show up on the web page. Everything still worked with MetaMask and all funds were exchanged correctly, but the message wouldn’t post on the web page portal.
After trying everything I could think of for 6 hours, I gave up and added another button to get the results. That worked, as seen above.
But I really want it to be automated without needing that second button click.
Does anyone have any ideas on what I can try to get the message to post automatically?
I didn’t post any of my code as I didn’t want to take up a massive bunch of space here in the forum with all of it.
I can post it/parts of it if anyone wants to see it to check it out.
Thanks!
Ben
Thank you for your response! Here is the part of code it is referring to:
This is where I declare the variable:
var wager = $("#bet_input").val();
And this is where I am using the variable, and where the error points to:
contractInstance.methods.placeBet().send({value: web3.utils.toWei(wager,"ether")
Figured it out! Here’s what I did in case anyone else runs into the same issue
var wager = $("#bet_input").val();
var bet = "" + wager;
contractInstance.methods.placeBet().send({value: web3.utils.toWei(bet,"ether")})
I guess using “” in declaring var bet sets it as a string.