Programming Project - Phase 1

Working on it :smile:

1 Like

Part 1:

Part 2:

  • WIP
1 Like

Thanks Dani, that was very helpful as well. I feel like I’m catching the events properly as I can log them to the console. But they are not displaying on the web page after the transaction occurs. Can you take another look and let me know what I’m missing?

Hey @Flaflaflohi

Whenever you have issues with your code, always check the console. It gives really good informations that will guide you :slight_smile:

Follow me:

  • I just run your code and I get this error:

  • In your main.js file, line 45 states:
    var receiptValues = receipt.flipResult.returnValues;
    it looks like flipResult does not have a property called returnValues.

What you have to do here is just to console.log your results step by step.
Start with console.log(receipt) then console.log( etc until you reach your result.
This is the right path, I suggest you not to copy it but to do it yourself as explained above.


Now that you can display it on the console, just show it in the webpage :slight_smile:

Happy coding,

1 Like

First coinflip dapp assignment:



1 Like

Phase 1 - I know it’s really basic, but I want to go on to oracles.

1 Like

A couple of screen shots of the coin flip dapp in action.

1 Like

It took me half a day to come up with the result, I thought it would be much quicker :smiley: Many lessons learnt. Cannot wait to try oracles.

After signing in with the wallet:



Owner only UI to fund the contract:

1 Like

Hi guys,

I have this getter function in my smart contract which gets the player’s balance. When I tried putting it in the browser format, it is showing me a weird set of numbers instead of the actual MetaMask balance (which is 85 ether).

The function works perfectly fine in Remix upon checking and the Truffle test shows no signs of problems too. What could be the cause?

Thanks in advance :slight_smile:

Hello guys, I’m having a bit of trouble with my project., the betting portion works well but when I try to print out the result it throws an error., here is a screenshot of the error.,
Can someone help me out?

Hello guys, I’m having a bit of trouble with my project., the betting portion works well but when I try to print out the result it throws an error., here is a screenshot of the error., @filip @thecil

Hey @newavel

Strange issue indeed.
Do you see the right balance when you console.log(res)?
To be honest I don’t see any errors in the screenshots you’ve posted, could you please upload and give me your github?


Hey @Mucha_Julius

Try to reset your Metamask account and check if it works after that.

Metamask > Settings > Advanced > Reset Account.

Schermata 2020-10-13 alle 15.41.37

It seems like your code is hitting a revert (), double check that too.

If you cannot find the issue create a repo on Github, push your code and send it to me :slight_smile:

Let me know,

1 Like

Hi, I did the reset, and now I have a new error :sweat_smile:

I have sent you an invite to collaborate on git hub

“ALERT: Transaction Error. Exception thrown in contract code.”

Did someone had similiar issue with metamask trying to execute transaction?
Only solution i find is to raise gas limit, but it doesn’t work…

I have the same exact problem., been wondering what to do

Hey @Spartak

Your smart contract is hitting a revert (). This is the reason of the error.
Can you show your contract code?


1 Like
import "./Ownable.sol";
import "./Random.sol";
pragma solidity ^0.5.12;

contract Flip_coin is Ownable, Random{

struct Game {
	bool betHead;
	bool isHead;
	uint betSize;
	uint payAmount;
	bool winBet;


uint public balance;

modifier betable(uint max,uint min) {
	require(msg.value <= max && msg.value >= min);
	require(msg.value <= balance);

modifier pay(){
	require(msg.value >=0);

event gamePlayed( bool betHead, bool isHead, bool winBet, uint payout);

function doCoinFlip( bool betHead) public payable betable(1 ether, 0.1 ether){
	balance += msg.value;
	Game memory newGame;
	newGame.betHead = betHead;
	newGame.isHead = flipHead();
	newGame.betSize = msg.value;
	newGame.winBet = didWin( newGame.betHead, newGame.isHead);
	if(newGame.winBet == true){
		newGame.payAmount = 2 * newGame.betSize;
		newGame.payAmount = 0;

	emit gamePlayed (newGame.betHead, newGame.isHead, newGame.winBet, newGame.payAmount);

function incBalance() public payable pay(){
	balance += msg.value;

function withdrawAll() public onlyOwner returns(uint){
	uint toTransfer = balance;
	balance = 0;
	return toTransfer;

function didWin(bool betHead, bool isHead) private returns( bool ){
	if(betHead == isHead){
		return true;
		return false;

function payout( uint betSize )private returns(bool){




I’m trying to make the contract as a multiplayer one. So the contract collects the bet from different players and then pay them out if they win.

I saved all the address of each player in one array playersArr and I used a mapping playersto link each address with the amount bet.

At this point I use a loop to pay all the winners.
I get an error using playersArr[x].transfer. It says transfer is only available for object of type address payable not address.

if I try with only one player I just write msg.sender.transfer and it works.

How could I make playersArr[x].transfer an address payable? and why it is not already?

    uint x = 0;
    while (x < playersArr.length) {
    balance = balance - (players[msg.sender].amount)*1000000000000000000*2;
    playersArr[x].transfer( (players[ playersArr[x] ].amount)*1000000000000000000*2 );


thanks :slight_smile: