Programming Project - Phase 2

@JeffE

The code you indicated calls a function in the provable API your contract descends from (is usingProvable). If you open this code and trace through (it can be confusing so take it slow), you will see it chooses a contract address based on environment (mainnet, ropsten, etc) and then executes a call against the remote contract. The remote contract knows the address of your contract (as this is the msg.sender it receives) and is programmed to execute the __callback function of the contract that called it.

Regards,

2 Likes

Thank you! Just want to make sure I do everything with correct conventions.

1 Like

Thank you so much! I appreciate it!

1 Like

I want to display the result on the webpage once the callback has been executed. In my JS file for my DApp I tried doing it with .then but this does not take into account the callback.

When the user clicks the start button the game is started:

contractInstance.methods.start(choice).send(config)

I was trying to run this code after:

.then(async function(){
        showResult();
    })

but this does not take in to account waiting for the back. What is needed to wait for the callback.

Thanks!

@JeffE
remove async keyword and try

1 Like

That did not work either, gave me an uncaught error. Been trying to look up how to wait for callback in javascript but do not seem to find the answer.

Or maybe I can wait for an event to trigger then I can call the function

Did this work?
Its difficult to say without looking at you full code.
You can upload a git link :slight_smile:

1 Like

I tried to figure out how to do this, but was not working. This is the last piece I need to incorporate then only thing left is a little more styling.

Here is a link to what I have so far: https://github.com/JExtor/CoinFlipDAPP

Thank you so much for the help!

@xactant

I was able review flipit_V1.sol

  1. Since there are no warnings too in the whole smart contract, it just executed perfectly.

The smart contract is so nicely written that there is very little scope of improvement :slight_smile:

Keep it up :+1:

2 Likes

Happy to say that I have now finished the 2nd phase of the Coinflip dApp!

Following submission of 1st phase of my project I got some good suggestions by @gabba to add some functionality into my contract like fund contract, view contract balance and withdraw funds from the contract - now all implemented as a part of 2nd phase.

I have uploaded my source code for review here: https://github.com/Filipo24/CoinFlip-Dapp

Feel free to comment and make suggestions for improvements :slight_smile: I will admit my focus was on implementing the functionality, but I know there can be better improvements made on handling errors, and adding require/assert statements.

I have added link for the video demonstration below (it’s quite long as I made shown all of the functionality and made 3 bets with first 2 showing as losing bet and 3rd bet was a win for the user):

@JeffE @Filipo24 will be reviewing your smart contracts and get back to you :slight_smile:

2 Likes

Thank you! I appreciate the help!

I think I figured it out! Instead of using .then
I messed out with using contractInstance.once and this seemed to work!

1 Like

Well I am close at least. I figured out how to wait for an event to be emitted, still working my way around, displaying the data I want.

1 Like

@JeffE
Amazing work!
I tried running your project but got stuck with some chrome content security policy issues :frowning:

Great to know you solved it :slight_smile:

2 Likes

I got it! So I created a function that gets the result from the callback and returns it.

I think the problem I was having though was that I thought every time I migrated I thought that this would update the code in the smart contract. But this is not the case. I had to deploy a new smart contract with the new code for it to work.

Is there a way to update the code once it is on the test net? Or when a smart contract is updated does a new contract have to be deployed to the blockchain?

Thanks!

1 Like

@Filipo24
I was able to review your smart contract

  1. Nice usage of private, internal, external, ownership
  2. Provable api is well used and you are checking the api price :+1:
  3. Great use of events in the frontend

The smart contract is very comprehensively written.

Point to remember

  1. You could add the SafeMath library and a proxy in the future
  2. Also don’t forget to call the provable_getPrice(“RANDOM”) function to update the balance of your smart contract after each call. Otherwise you will have an issue at some point.

anyway this is just details it’s a really good project overall so well done :+1:

1 Like

@JeffE
Once the smart contract is deployed we cannot update that same contract ever again but there are work around to update a smart contract is known as proxy/upgradable smart contract

resource:

  1. https://medium.com/@adilharis/upgradeable-smart-contracts-made-easy-4134bb72fe6
  2. https://medium.com/@blockchain101/the-basics-of-upgradable-proxy-contracts-in-ethereum-479b5d3363d6
2 Likes

Thanks @Taha for the feedback!

I am actually going through the Smart contract security course as we speak, so already recognize that SafeMath library could be used to protect the contract a bit better :slight_smile:

1 Like