Hi @Illidan7
Try a truffle deploy reset
truffle deploy --network ropsten --reset
Hello @Illidan7
It seems to be an error in your deployment file what is the name of your Smart contract .sol file
Can you share the migrations file related to this file ?
Congrstulations, nice job. Iāll make sure to try it out.
Having an issue testing the provable api my function fails saying
transact to Flip.flip 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 have a balance in my contract and testing on remix using the standard import on github error seems to be on the call to provable_newRandomDSQuery no idea why its telling me to make it payable
function flip(uint call) public payable {
// call either = 1 or 0
require(msg.value >= 100000000000000000,"the minimum bet is 100 finney");
require(contractBalance >= 100000000000000000,"not enough funds in contract");
uint value = msg.value;
contractBalance += value;
uint256 QUERY_EXECUTION_DELAY = 0;
uint256 GAS_FOR_CALLBACK = 200000;
Game memory newGame;
bytes32 queryId = provable_newRandomDSQuery(QUERY_EXECUTION_DELAY,NUM_RANDOM_BYTES_REQUESTED,GAS_FOR_CALLBACK);
newGame.player = msg.sender;
newGame.bet = value;
newGame.status = false;
newGame.playerCalled = call;
gamePool[queryId] = newGame;
emit LogNewProvableQuery("Provable query was sent, standing by for answer.");
}
Hello sir, could you send me github repository I have a feeling you have issues with your __callback function as this seems okay.
Hey thanks for the confirmation figured it out i needed to change remix environment to injected web3 with metamask on ropsten network.
Hi Filip,
I sent my code (see above).
It allows the player to have a balance in the contract and to decide when to withdraw it (while leaving the owner the ability to withdraw only amounts that are net from obligations to players).
It shows the player his balance after flipping and gives the owner the ability to see the total contract account balance and his net part of it. seems to work smoothly, however,
I am sure that a lot of things can be done better, and because I started to code only through 'taking courses in
Ivan on Tech Academy" I will be more than happy to get some feedback and
suggestions for improvement.
It is amazing how much I learned in the courses in this academy (from scratch, even though my experience as a financial advisor /modeling complicated models on excel may help).
Really thank you. grate course.
What you recommend as the next step (in order to become good enough to start coding professionally smart contracts (even as a beginner).
Thanks
also to gabba and all the others )
Hi @Guy
Sorry i have been really busy this week working on the chat.
I ll try to test and deploy your project this weekend if @ivga80 donāt .
You can start to look at the smart contract security course you will learn a lot. This course is great.
Hi @Guy
I played a bit with your smart contract this morning
Well done but there is still few things you can improve.
The event listener works perfectly, a lot of people have issue to implement it but yours works fine.
The obligation variable is a really good idea.
The reset function is a good idea in case there is a callback issue but i think it should be only owner, the owner should pass the user address. Because if the user can unlock itself this security precaution doesnāt make sense anymore.
Regarding the frontend there is few function not implemented:
numberOfGames()
/ only in solidity
playerBalance()
/ An important one ! i had to call it from the console to display the value in the screen
There is an issue with your variable
newBet.creator
because it s global and set on the last flip, so if you play and i play after you you ll not be able to withdraw because
function toTransferBet( ) public returns(uint) {
require (msg.sender == newBet.creator);
The value of newBet.creator will be my address, so you ll have to play again to be able to withdraw.
The ownerObligoToPlayers/ accountBalance variables have an issue caused by newBet which is global.
If one player Flip the value of newBet.betAmount will be letās say 1ETH.
This code is updated only when the callback is called by the provableApi.
if(randomNumber==1){
playerBalance[newBet.creator] += (newBet.betAmount)*2;
ownerObligoToPlayers += (newBet.betAmount)*2;
}
Now letās say an other player play before this call with 0,1ETH so
newBet.betAmount = 0,1
When the callback will be resolved the first player balance will be incorrect, he will only win 0.2 ETH not fair hum !
Also you are substracting
acountBalance = (address(this).balance-ownerObligoToPlayers);
twice which lead to a wrong state of your variable.
As you can see the contract balance is 2.374 but the owner balance 1.1579.
It should be zero because you own me 2.8 (or minus eheh but i ll explain this after )
So the last issue is your are not deducting the price for the provable api call.
Look on their website their is a function
provable_getPrice("RANDOM")
Double check the value of random i forgot if it s capital letters or not , you can find it in this topic i guess.
So now you own me 2.8 eth but i canāt get it back because your contract only have 2.374 left. So iām gonna call Fake satoshi and sue you !
I know from your posts that you just start to code with iot course and itās amazing that you are already able to build a Dapp with a frontend, a backend on the blockchain, using asynchronous call and all this stuff. This is a lot of new things to learn. So well done to make it until the end of this project.
Hi. really thank you.
For the compliments (ā¦yes, I assume that I have the required obsessivenessā¦) and for the educated improvements and corrections. Of course, I will go over it (and the security course) and improve it as necessary.
hi sorry, i solved it, (some deployment problemā¦)⦠thanks
Hand in for Phase 2
Hi gabba ,Filip and everyone
Here is my upgraded code, taking into account most of gabba remarks. please review.
Thanks again for everything
Hi Gabba
I posted my corrected code below (after changes I made as result of your suggested educated corrections)
few issues for your attention:
https://github.com/GuyBarkay/CoinFlipProvable
If possible, please review. I am learning (and enjoying) so much ā¦
Thanks again
Hi @Guy
Great i will look at it this weekend and come back to you
Did you start the eth security course btw ?
Yes, I did. I even used some lines from safe math.
Here is my dapp on github, It was a great project. I have learned many thing.
Thank you Flip and Ivan.