I did run it on the port 8545, through truffle migrate, I’ll check whether logging out and restarting the server and the page helps, I’ll let you know, I’m feeling a bit helpless, all I get are errors and I spend hours on Stack overflow
I got this error many time when developing it s really annoying. When did you get the error ? Did you send fund to your contract ? I tried it on my side with the function i sent you and it works.
@gabba I’ve tried everything, I still get the same error when calling the bet function from address accounts[2]. It used to work with regular GUI ganache, what didn’t work was the listening of events, not the transactions themselves. Now I did the same on the GUI, the transaction worked, everything under the hood worked as expected, however I still don’t see any bet event appearing in the console, it outputs and empty JSON object. I can’t even get the return value of the flip function. When I open the transactionInstance JSON, under events, bets, I see this error TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:1:142)
, I tried playing with the truffle console and I can see the events happening in the logs, they just don’t show in the console.
@gabba THANK YOU FROM THE BOTTOM OF MY HEART, I can finally rest, it worked!!! I inspected the javascript source of my server in the browser and there were cached versions of the main.js
file. It turns out I was running the same wrong file again and again. I feel so stupid, but I’m glad I figured it out.
Great i’m glad you solved it
Ok, this was cool! From 0 to a full dapp with 0 previous experience besides this academy courses. I was a Backend Developer before, though…
My code: https://github.com/PedroMD/eth201-coinflip
Screen recorder: https://recordit.co/LSFDuiwX2I (can record a simpler one, if needed)
In one of the videos, you mentioned the use of emit to get the web app to know what the SC did, so that’s what I’ve implemented… Is this the right way to doing it?
Hey guys! Any tips before starting the project? I have no experience as a developer at all so any suggestions on how to start would be much appreciated. Maybe start some solidity code on Remix? I guess I should not use the old Ethereum course as reference even though Filip made a similar dapp there, ritgh? I also see most of you uploaded it through github, should I use it?
Thanks a lot for your help!
Hey y’all, I’ve done a lot by now but I’ve come to a point where I am stuck with an error. I’ve got my button to fire Metamask but I am always getting the same message:
I guess my function flipCoin() is kind of funny (although I wrote iton Remix and was compiled). I tried to run a Unit Test but is also failing.
I just saw a tutorial on how to upload this on Github so here’s the link: https://github.com/pedromndias/Coinflip Btw, any recommendations on how to update it after changing the code on ATOM? (If so, should I do it every time or just like when I want to post here?) Maybe @gabba could give me a hand? I wrote comments on the mainCoinFlip.js and CoinFlip.sol so my way of thinking can be seen.
As I wrote before, I have no experience as a developer so all the front end (had a lot of fun designing it!), smart contract etc takes me a lot of time. But I am learning a lot since I have to figure out all this stuff without @filip explaining!
Thanks a lot for any help
Hi @pedromndias
I ll try to clone and test your project later today but i think their is an issue in your if:
if (playerGotPaid = true)
should be if (playerGotPaid == true)
I ll check if i also have the metamask error ttyl
Edit: to update your code on github you should do this
To get a list of the modified file you can do a:
git status
Add the modified files
git add <YOUR FILES>
You need to add a message to explain the modification you have done:
git commit -m "<A MESSAGE EXPLAINING YOUR MODIFICATION>"
Then to send your modification:
git push
Wow, Love seeing all your projects here! Amazing work everyone
hey @gabba! Thanks a lot for the help. I think I managed to update the repository on github using ATOM (I can now see the changes I made).
Changes I made:
-
Completed the code for the mainCoinFlip.js file but I still have an error with Metamask.
-
Updated my CoinFlip.sol with a getter function for the javascript file. Also updated the logic on the main flipCoin function.
-
Updated the abi.js since the json files got modified after recompiling my contract (Should I? Because I was not seeing my new function on the methods (console.log(contractInstance)) so I figured had to change the abi).
So the errors I get are:
And this one:
If you could please take a look, I feel I am almost done with this Phase 1!
Thanks a lot for your help so far
Hi @pedromndias
Can you try to change your config for the flip function with this :
var config = {
value: ethAmmount.toString(),
gas: 21000
}
Hey @gabba! Thanks for the help, I got rid of the gas error and now I can see the result of the console.log(res) of my getResultOfGame.
But I still don’t get the result of it in the browser after the word “Result”.
Metamask shows the following error (and I reset the account already):
I find also curious that the result of the game is always “0”, did also a printscreen to show you:
Did the app run good when you tried it?
Thanks a lot for the suggestions, almost ready to phase 2!

Hi @pedromndias
How are you sending funds to your contract ?
Their is no funding function and no payable constructor.
You should add a payable constructor and send fund to your contract when you are deploying it, or add a function to send funds to your contract.
add this:
constructor() public payable{
owner = msg.sender;
}
And deploy your contract on remix with 1eth.
Before testing your contract with the web3js function try to test it with remix an check if it works.
I just see 1 test in your project, did you skip the unit Testing part ? (it’s an important one)
Because you will be able to make sure all your web3 calls are working.
hey @gabba thanks for replying. Did you get the chance to clone my contract as you said?
I have that constructor in my Ownable.sol contract, which I inherited to the CoinFlip.sol. So I thought that it was the funding function. I added “payable” to it but the error remains the same.
I wrote the contract in Remix and it worked well. I inspected all the logs and the getResultOfGame function works good. But the test I wrote is not working that’s why I didn’t do any more tests. I am trying to get a well-coded contract so I can start with the tests.
Once again thank you for the help!
Hi @pedromndias
Sorry for my late answer, yes i deployed it with my modification and it was working.
You also need to add a payable constructor to your CoinFlip.sol contract.
It will inherit from your Ownable.sol constructor.
I am at work now but i ll try to open i merge request to your repo tonight.
hey @gabba, thanks! Let me know if you can open / merge request.
Because I tried introducing that constructor but still not working:
In case you can open, can you spot the error on my unit test?
Btw, you work as a developer??
Thank you once again
Hi @pedromndias
My first message was to avoid your metamask error with gas but it was miss leading sorry. Metamask will require minimum 21000 (by default it could be less) to send a transaction but it can be more if you are calling a smart contract function, try this code.
var ethAmmount = $("#eth_ammount").val();
var amountInWei = web3.utils.toWei(ethAmmount, "ether");
console.log("Ammount of ETH inserted: " + amountInWei);
var config = {
value: amountInWei,
gas: 100000
}
There was few issues, first parsing your input in int can cause a problem because if you send 0.1 it will be converted to 0.
Next it s better to convert let’s say 0.1 in wei you ll get 100000000000000000 which can be pass as a value of your transaction.
Then i use 100000 of gas to avoid your function to run out of gas. The remaining gas will be return to your address.
To make it simple deploy your smart contract on remix and send 1 eth.
Do a truffle compile
copy the abi from the Coinflip.json generated file into the abi.js
Then copy you contract address in new web3.eth.Contract(abi, YOUADDRESS, {from: accounts[0]});
it should work :
https://ropsten.etherscan.io/tx/0x4a260db101170ec3d1991ac5a9e0ca4db285861adbdfbcb0548148ff5e6ff708#eventlog
this is a transaction i made after having deployed your smart contract. The event is called as expected.
Hey, @gabba thanks a lot for checking!
I went again on Remix but it was working fine just like before (just updated the withdrawAll function to payable so it could work, as per the error log).
Regarding the localhost, why does it show like this and not directly the webpage?
Regarding the tx issue, I did all your steps and then reset the account on Metamask and did Ctrl+F5 on the webpage. And it looks like the tx is being created! But as soon as I hit the button, there’s an " Error: Returned values aren’t valid, did it run Out of Gas?" I sign it and it is confirmed but also there is no “Result” on the webpage:
So I guess at least now we have a transaction but still no response from the network to the website…
Thank you!
Can you link your transaction hash ?
For the localhost you need to run your server where your files are located so inside CoinflipDapp and name your file indexCoinFlip.html -> index.html
You github project wasn’t update since 8 days so i think your push didn’t works. I was only able to run your project with the last version