Programming Project - Phase 2

Hi @dan-i
The coin flip contract address is 0xA7069Acd9e0C4fB4Df2d8eBfA380f0Eef9d718da .
How long does the request usually take?

Hi @paddyc1

I’ve tried now and indeed the oracle is not responding, this happens quite often with provable api on Ropsten.
I have created a guide to get a random number using chainlink, check it out: Generate a random number using Chainlink

Happy coding,

Cool! I’ll go try on Kovan.

1 Like

Here it is deployed on Kovan, using the Chainlink random number.

Here’s my Github repo:
And here’s the demo video, sped up:

Any feedback on bugs/vulnerabilites would be appreciated.

1 Like

Hi @paddyc1

Well done :slight_smile:

The contract looks good, just a little suggestion:

            uint256 win = winAmount[msg.sender];
            address payable player = payable(msg.sender);

            contractBal -= win;

In Solidity you should always use a security pattern called check -> effect -> interaction (this is explained in the smart contract security course that I suggest you to take if you did not already).

Withdraw function should be something like:

function withdraw (uint _amount) public {

    require(userBalance[msg.sender] <= _amount); // check
    userBalance[msg.sender] -= _amount; // effect
    payable(msg.sender).transfer(_amount); // interaction


Happy learning and good job,

1 Like

That makes sense. I’ll take the smart contract security course next.
Thanks for your advice, it makes all the difference.

1 Like

hey @dan-i @thecil ive had some issues deploying to ropsten testnet. Its annoying because i have deployed my game from the ethgame course to ropsten again as a check and it works but when i try to deploy my code for this i get this weird error.

And my rospsten account has 6 eth in it so i dont know how that message is coming. If yous have seen an error like this let me know a possible fix i would greatly appreciative theres not much good info i could find online,

1 Like

Hey @mcgrane5 hope your good man.

Ok what about the truffle config? could you also share it here? maybe the contract also :face_with_monocle:


hey @thecil good to see you man. Ehm I can just link you to my git repo. My code is very much under production so im well aware im that is not the cleanest code, missing requirres(), evenets etc… All things i will add towards then end as most of my time until now was on the front end. But yeah dont think its the contract causing the issues its a weird one . Anyway thanks for having a look

Hey @mcgrane5

What’s the address that is deploying the contract?
Also just to be sure you have not pushed any sensitive info, I checked the private key you left in the config (please do never push PK and/or mnemonic on github and considere both of them burned).

The PK has 6 eth, but you are deploying using the mnemonic in the .secret file.
How much eth do you have in that wallet (address[0])?


hey @dan-i, the 6 eth is in address[0] a.k.a the top address in ganache. And thats the account deploying the contracts i doubled checked the migrations summary anyways so thats fine. So surely the contract doensnt cost 6 lol but Its weird im clueless about what else to change because there was not much information online for that error that threw. Mad to get try this oracle sus lol hahah

ohhh and also so sorry yeah i should never have uploaded that i actually didnt even realize because i did a git add --all to push, to my code just for the purpose of this post so peolple could have a look and obvs the secret key got included. I usually just push my files one by one if ive made any noteworthy changes but Thanks for noting that i didnt even realise i had it up on github

The address that is deploying is: 0x59C6c942cB04fe92743D40dF4A92B55E69B3D6C8
This has 0 eth :slight_smile:
Screenshot 2021-06-03 at 11.51.26

You can see the address by console log in your migration:

const Migrations = artifacts.require("Migrations");

module.exports = function (deployer,n,accounts) {

I sent 0.5 eth to the address I and I was able to deploy (contract: 0xE81F0242A29e807528f3E099824b6Ceb640C38d3)

1 Like

awwww @dan-i brilliant. Thank you very much for that. I was sure i was using the right address, perhaps its because i was going off the summary from my local chain deploymemts, just thought the address was the same. thanks my dude


You are very welcome! Can’t wait to see the final result


yeah im excited to finish it now too, ive finished the front end functionality since that last post and the UI is even nicer. I just have to adjust my code now for this oracle thing which is looking like its going to be a major refactor but we do love all the coding we can get :stuck_out_tongue: hahaha.

Theres actually just one little querey daniele that i had. So the current, “old” version of my code only allows the user to withdraw the contract balance which is in my case, is equal to whatever the player inputs as the bet amount. If they loose its gone, but if they win they can actually only withdraw that msg.value amount which was initially sent in, as it currently stands anyways. So obviously i would like to initialize the contract with a payable function that deposits some amount (msg.value) which acts as the contracts reserve so that the contract can afford payouts. But where does this money come from you cant just pull it out of thin air certainly not on the testnet. So what way could i initialize the contract reserve balance. Like a cheap way would just to be to initalize it with funds from a different address but im not sure about that it, or maybe that is the way to do it i dont know. Have you any suggestions.

Hi @mcgrane5

You should definitely implement a deposit function in your contract, otherwise you wont be able to payout the user in case of a victory.
Keep in mind that the payout is msg.value * 2 therefore your contract should (require) enough balance before the user can play.

If this was a real casino game, then the contract owner should be the one depositing ether in the contract to make sure it runs correctly.

In our case you can just allow any player to deposit ether.

Let me know if this answered your question

1 Like

yes it definitely did thanks as always my g. Ill keep you updated

1 Like

Hello everyone So i finally finished my betting dapp and wow i surely learned a lot. I have a link to the
video below Its quite a long video because give an in depth explaination of all the different features i added, aswell as aspects i struggled with and things i would have done differently. So if you dont mind me talking for 10 mins please give it a look and also get to see my dapp in action

. @dan-i, @thecil you guys are the experts here if yous could take a look at my code and provide any feedback critics i would be very grateful espcially in terms of optimisation or security.

I have pushed the current state of my code to git hub please only referance the chainLinkOracle branch thats my main code base.

Overall i learned a lot especially with handling edge cases i tried to handle as many as i could to prevent users from breaking the dapp logic. See yous in the next one guys.

Link to video of the dapp (sorry for bad audio

Github repo link to source code (ChainlinkOracle)

Github repo link to source code (ProovableABI Oracle)

Scrrenshot of UI

dapp screenshot.PNG

Disclaimer about the html and css
For those of you who decide to look at my code note that this was the first time i ever wrote a a front end or webpage and never used html of css before other than other courses ive taken here. So everything that i included was learned on the sport from forums and youtube videos. So my html and css files are very unstructured and written poorly (think of it like a jigsaw puzzel where the wrong pieces are matching or forced together). Although the front end doesnt look to bad as a final product my css is not great i used way to many classes and there is a lot classes which use the exact same code for different buttons (the popups are very guilty of this, there s about 5/6 different popups each with there own class and onclick function in js. I should have made maybe two popups and 2 functions and just adjested the text content by using empty span elements instead of hard coding in the text in the html file). Obviously im aware of this now and because i learned so much and if i was to do a front end for a new project it would be much better or even if i was to refactor the front end for this with what i know now i would say i would be able to cut down my css files by half as there is around about 1400 lines of css for this front end which could probably be achieved in 5 or 600 lines maybe less. Even the CSS files look bazar to me at this point from the lack of thoughful class names and descriptions. But its all a learning progress. Im very motivated now to make a front end for the DEX project so stay tuned for that. Anyway thats enough reflection on my part. Thanks everyone and stay safe

Happy coding

1 Like

This looks amazing man!, I’ll reviewing it this weekend and give you a feedback about it :nerd_face:

I was not able to see the video, apparently im not authorized, would be a possibility to make it public?

Carlos Z

1 Like

Hey @thecil, i dont know why that happened. I uploaded it to youtube instead just there. This is th elink you should be able to see.

Link to video demo

Chhers i appreciate that.


1 Like