@Taha
Looking at some previous peoples posts, I;ve created the code below so far:
pragma solidity 0.5.12;
import "./safeMath.sol";
contract CoinFlip is Ownable {
mapping (address => uint) public balance;
function getContractBalance() public view returns(uint) {
return address(this).balance;
}
function flipCoin (uint) public payable returns (string memory, address) {
require(msg.sender balance >= msg.value, "The users bet cannot be more than users balance");
if (random() == 0) {
//Winning
uint win = safeMath.mul(msg.value, 2);
msg.sender.transfer(win);
} else {
uint lose = msg.value;
this.transfer(lose);
}
}
function withdrawAll() public onlyOwner returns(uint) {
uint toTransfer = balance;
balance = 0;
msg.sender.transfer(toTransfer);
return toTransfer;
}
function random() private view returns (uint) {
return block.timestamp % 2;
}
}
I will start by saying that I feel as though I dont know as much as I should at this point which is somewhat frustrating for me personally. Looking at what I’ve created so far, which i know doesn’t totally work yet… I have the following questions:
-
If the user loses, how do I transfer msg.sender.value to the contract itself?
-
How do you determine what the functions modifiers should be and what/if it should return anything
For example, I saw different people have different inputs and returns for the coinflip function and i dont understand the differences or why you would chose to do it one way versus a different way.
I love that we are building something on our own and forced to figure it out because i feel that really helps you to learn and understand what you are learning, however I do wish there was a basic outline( create mapping for x, then create function to do y, etc.) even if its purposely vague, but at least making you think out the problem a bit more.
Would love some feedback/guidance from the community here. I’m going to keep trying to improve this in the meantime.