Programming Project - Phase 1

I copied the tx hash and it is:
0x8e7a248473f0dee9308f7b5459bd4db0e11f8df25a3cf5b8092a37602cd5f112
Will you be able to check it? Because it is running on my local node Ganache.
Should we continue this conversation with a personal message? The forum is suggesting that we do it since I’ve replied 3 times to you in this topic already.
I did not update github since the only change was the constructor, but now I already did the push (about 10 minutes ago but still not updated on the web).
image

My dapp in action:

Never been a UI wiz, more a backend guy, it shows. Others are so much better at this, but still I got to glue everything together and working.

2 Likes

Hi.

This happens when you start the python -m http.server in the main folder. You should start the webserver inside the Dapp folder.

I tried to run the code to in remix and it worked for me. I suspect that the issue is generated when you deploy the contract in truffle. Do you initiate the contract with some funds? If you deploy the contract without any funds, how will the contract be able to pay out if the first cointoss is a win? Have you triple checked that the smartcontract address in the main.js is correct after a new deployment? All those smal things that’s easy to forget?

The next step I would take is to spilt up the code in parts and try to catch what causes the issue? But you must make sure that your contract is funded or else it can’t payout the ethamount*2 if the player wins the first cointoss.

Ivo

1 Like

Hi @ivga80! thanks for replying and checking my code :slight_smile:
@gabba told me that the localhost file should be called just index.html and not coinFlip.html because I was doing python -m http.server inside the Dapp folder but it moved one folder up by itself.
This could be helpful for future students!

Regarding the code itself, it worked fine for me in Remix (that’s where I wrote the contract) but yes, you are right about the funds! @dan-i wrote to me 1 day ago and also tried my contract (thanks a lot!) and mentioned the fact that I have no initial funds! Now I am rewriting it to correct it. So yeah, thanks for noticing the initial funds issue, makes total sense :slight_smile: This could be also helpful for future students.
The next step will make sure to write some good unit tests and then if all good move to phase 2!
Thanks a lot!

1 Like

So I just repeated what the others said already?
That only shows that I didn’t read all the posts on this issue before testing and trying to help out. :see_no_evil:
I’m sorry, that’s my bad. :roll_eyes:

I wish you good luck and happy coding the rest of your dapp. And feel free to ask for more help and I’ll be quicker on the trigger next time, I promise. :hugs:

Ivo

1 Like

I lost quite some timeg on an annoying issue on the latest OSX. Providing the solution here because others may run into it as well. While running

npm install @truffle/hdwallet-provider

I got compilation errors about node_gyp … it seems scrypt is unmaintained and incompatible with node 12 and 13. Downgrading node to version 8 was the only solution I found. Did it like this:

brew uninstall node
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
nvm install v8.17.0

then in your project folder:

rm -rf package-lock.json node_modules
npm install @truffle/hdwallet-provider

Now node_gyp compiles fine.

3 Likes

Hi guys, so the contract works in remix, but it doesn’t fully on the web page, if the player wins, the dapp in the web isn’t paying him, I get the “you won” print, but not the transfer, here is the code:

caller is addres payable.

Any ideas why this works on remix and doesn’t on the web?

Hi.
Do the contract balanse have enough funds to pay out the 2 ether?

Ivo

Yes it has a top up function.

I call it with a button, and it takes the 5 ether from the metamask wallet.

2 Likes

Hi All, Struggling to get my contract working. It could be a deployment issue? It has never reacted when I click the buttons on the webpage. If anyone could give me some pointers, I would really appreciate it!! Happy Easter.

The link below is of the Chrome console once I ran the webpage.

dd|690x257

1 Like

Hi.
You have forgotten the semicolon ; after your jquery code.
$("#deposit-button".click(deposit);

I don’t know if that’s the solution to you issue, but you should could try and see if it helps?

Ivo

1 Like

Thanks for the quick reply, I don’t believe that this is the issue but I will try again with the semi-colon.

If you have any other pointers, any help would be greatly appreciated.

UPDATE Please see the screenshot of the console after I did a refresh and added the semi-colons. Deposit button still not working.


Saoirse

Here’s a link to my github in case you wanted to be able to c&p:

Thanks a mil for anyone willing to help.

1 Like

Hi, we have a goal to test all the assignments, but this Easter the number of questions and students in the forum has just exploded. :hugs:

Please have patience with us and we will reply to all.
AND to all other students, we encourage you to help each other with what you know. This is a perfect opportunity to start working and collaborating with other students. :wink:

Ivo

2 Likes

Hi @pmk
Did you solve your issue ?
Where is your variable caller declared ?
Try to initialize it in the CoinFlip function.

address payable player = msg.sender;

Add a check at the beginning of your function to make sure your a sending the eth correctly
require(msg.value >= 0.01 ether, "bet should more than 0.01 eth");

2 Likes

Hi @saoirse

First you shouldn’t trust the user input

    contractInstance.methods.flip(betType, betAmount).send({value:web3.utils.toWei(betAmount, "ether")})

should be

    contractInstance.methods.flip(betType).send({value:web3.utils.toWei(betAmount, "ether")})

In your smart contract check the value with msg.value, remove the betAmount because player will be able to cheat by sending a small amount to your smart contract, and set the variable betAmount with a big value.

You error is you are calling your id in the front with a #.

    <button type="button" id="#flip-coin">Bet!</button><br>

Should be

    <button type="button" id="flip-coin">Bet!</button><br>

your jquery are calling

    $("#flipCoin").click(flipCoin);

The # in the front of the name just mean it’s an id value.

2 Likes

Thanks a mil Gabba, greatly appreciated! I will work on the security bug and the id fix now.

You’re a legend!

1 Like

Hi again @gabba ,

When making changes to the contract file, will migrate --reset be enough to carry the changes over.

flip() is still looking for 2 parameters (from chrome console)even though I have made the suggested edit to remove betAmount.

Hi again
Yes it should be enough
Look at the abi.js file if the function have been updated. Otherwise change this file

2 Likes

1 Like