Programming Project - Phase 1

Welcome to the forum discussion for this section. Here you can ask questions or post feedback about the projects first phase.

2 Likes

Here is my version of the BetDApp. https://github.com/MaxiIT/BetFlipDApp/tree/Phase-1
By far it is not finished yet but feeld like that I already can show you the first version. I will impove this as far as i can in the next days and weeks.

1 Like

Great job!! Thanks for sharing. Could you share some screenshots of it in action? :slight_smile: Would love to see it visually as well.

Hey, I am currently testing the ways to make flexible-size bets.

I have a question for you guys:

  • How do you convert an integer value to Ether value? -taking a function parameter and turning it into Ether?

Thanks for the help!

Sure. Its not really impressiv but hey, it’s working. :sweat_smile: Here is a screen record. Hope you can play the video. https://drive.google.com/file/d/1GxtFia6u6zZ_9OWohQsb2DEwxI0o-tv5/view?usp=sharing
Still struggling to finish phase 2 now. :woozy_face:

1 Like

Could cou please specify your question I didn’t quite get it.
What is your integer value corrently represent?
Is you question related to your solidiy contract or JavaScript file (web3)?
In web3 you can do something like this

web3.utils.fromWei('VALUE', 'ether'); // 1000000000000000000 => 1
web3.utils.toWei('VALUE', 'ether'); // 1 => 1000000000000000000

https://web3js.readthedocs.io/en/v1.2.0/web3-utils.html#towei

2 Likes

Here’s the link with my DAPP interaction: https://drive.google.com/file/d/15Q2r9tSyyr-5zPSuFvYHTh0FsvmANlbJ/view?usp=sharing

I also encountered one problem which I believe is an inherited Metamask limitation that prevents sending funds from the contract’s address to the player when the winning event occurs (as intended in the code). Any thoughts about this?

1 Like

Hey, good job! Looks good :slight_smile: Good luck with phase 2 :smiley: It’s a challenge.

2 Likes

Goo job! I like your design :heart_eyes: Could you post your code for the claim/withdraw function? Seems like there is some error there.

1 Like

You can check the entire code here: https://drive.google.com/open?id=1P0TKLZJ1mab-kf1xdzHvKCm4cBsc_2J0L0Wg5hr6R_Q

getPrize( ) function is the one. Works fine on Remix though.

There is some error thrown from your contract. Are you sure it had enough balance to pay out the bet?

Keep in mind though, you have quite a serious flaw in your contract. You save the result in a single bet variable in the contract. What happens when 10 players play at once? All of their results will be added to the same variable. And then anyone can call the getPrize function, and get all the balance.

I believe, there was enough balance in to pay out, yes.

Will try to upgrade…

Hello.
I’m posting this here in the hope that someone can help me?
This is the 4th time I fxxx up the code in my contract, so now I begging for help from my fellow students before I destroy it again…

I appreciate all the tips and help I can get.

Thanks.

link to folder:
https://drive.google.com/drive/folders/1gtUi4YLJwHt2WEMBdHLLa-hXu_LS_oJl?usp=sharing

@filip. I sent you a PM the other day and I wonder what is the preferred way to get 1-on-1 programming support when we’re completely stuck?

Hey Ivo,
I’m just about to have a look on your code and try out your DApp. I’m kind of envious, it looks so nice :blush:.
But I have to ask you. Where exactly is the problem? For me it looks like that this almost workes fine, except of the missing payback/payout after winning.

Edit 1: Ok…now i got the problem…

Edit 2: I’m really not sure at this point as I’m confused myself a bit because of that. But i feel like that one of us is misusing the ownable modifire.

Here is how i understand the ownable modifire from the ownable.sol file:
The ownable modifire should be used when a function should be just executable from the contract instant creator.

constructor() public {
        owner = msg.sender;
    }

This code is just executed once when the contract is migrated. It defines who (which address) is the initiator. That’s why I have renamed this modifire in “onlyContractOwner” to make it more clear what it means.

Now, when I got it correctly, you have tried to used this modifire to prove if the Player is the owner of the bet. But in real you proved if the player is the contract owner.

Please notify me if I’m wrong.

Here is what i had changed as example. Not sure if this is correct but I hope it can help.
https://drive.google.com/drive/folders/1wZPSTR_A8MXi4yOJeGCxZfogKCg3lSPi?usp=sharing

2 Likes

I think that will solve it yes. If not @ivga80, post again and explain in more detail what the issue is :slight_smile:

1 Like

Hi.
@Paultier It was so late yesterday when I quit so I completely forgot to say what I need help with. :slight_smile:

@ I’m struggling to pay the player and I couldn’t understand who the msg.sender was and it was just confusing to me.
I haven’t tested your solution yet, but if Filip says it’s right, that’s probably it.
So THANK YOU for your help so far. :wink:

As I think, I still have to solve this issues:

  1. If the player wins, BetAmount * 2 will be paid out as a prize to the player.
  2. Where should I get the actual winnings from?
  3. Move value from contract balance to a winning address as mentioned in the above?
  4. Complete the last UnitTests.
  5. Test that everything works in the browser.
  6. How do I test security errors that can occur if multiple players are playing at the same time?

I’m also thinking of changing to a separate struct Player and adding struct Bet as a bet array in struct Player. To something like this:

struct Bet { 
   uint id;
   uint playerBet;
   uint playerChoice;
}

struct Player {
   uint id;
   address payable playerWallet;
   Bet [] bets;
   // Array with each betPlaced of individual Player
}
mapping (address => Player) private players;
// Mapping contains multiple Players with individual bets

Or maybe I shouldn’t, because it`s all the changes I make that fxxx it up every time. :slight_smile:

Some last questions to @filip.
Is it true that I can think of a structs in Solidity in the same way as classes in Python? Because then is it better for me to create each struct and associated functions in a separate file that I import into the “main” contract where I just run function-calls from?
Will that eliminate some of the security issues that can occur?

Thanx again for the help so far!
Ivo

2 Likes

@ I’m struggling to pay the player and I couldn’t understand who the msg.sender was and it was just confusing to me.

If you want. You could make a git repository so that we can build together on your project. I would love to learn more about how to use GitHub. :smiley:

I haven’t tested your solution yet, but if Filip says it’s right, that’s probably it.
So THANK YOU for your help so far. :wink:

You are welcome. Basically I have removed the onlyOnwner modifier as I think that it was misused at this point. Please correct me if im wrong. As I said, I don’t feel that comfortable. Than I tried to create an other modifier which should fit to your purpose. Please check this aswell, if this is correct. And I think that you had mistaken the accounts indexes in the Unit Testing.
I haven’t solved further issues yet.

I’m also thinking of changing to a separate struct Player and adding struct Bet as a bet array in struct Player . To something like this:
…
Or maybe I shouldn’t, because it`s all the changes I make that fxxx it up every time. :slight_smile:

Good question :sweat_smile:. Maybe try to simplify your code instead of building more complexity in it. I think this makes things easyer. But I guess it is the best to do whatever you feel the most comfortable with. :upside_down_face:

1 Like

Hi @Paultier.

I am a little busy today, but I managed to upload the project to my GitHub.

It is an “initial commit” so don`t expect much from the files like README.md.

You are welcome to take a look and collaborate with me, as long as it is ok for @filip and @ivan. Collaborating isn`t considered as cheating right?

Ivo

2 Likes

Hi @ivga80,
thanks for sharing your repository. I just made my fist pull request :blush:
But don’t expect too much and please let me know if I could do something better. And let me also know if you need further help. I would be happy to help, if I can, but I also don’t want to anticipate your learning process.
I think you are on a very good way. :slightly_smiling_face:

2 Likes

Congratulations on your first pull request. This is just the start of something big, @MaxiIT.

It was a pleasure to help you lose your Pull Request virginity.
By the way, this was my first too. :wink: :partying_face: :partying_face:

2 Likes