Etherum contract - world cup 2018 bet

in #cryptocurrency6 years ago (edited)

World Cup 2018 bets with Ethereum contract



On June 14, the world championship in football begins. As I am a football fan and software developer, I have decided to check out if we can make fair bets without charging a commission using an Ethereum network.

I have created contract which you can download from my Github https://github.com/SebastianDabkowski/Blockchain/tree/master/SD.WordlCupBet

In Poland, every bet omitting the licensed company is illegal so I can not publish this contract on the main Ethereum network. But for test purposes I have published it on Robsten (test Ethereum network).
If your country allows to organise bets whitout any special licenses, feel free to download and publish contract on main Ethereum network. If you do so, please send contract address to me at [email protected]

Technical details:

pragma solidity ^0.4.23;

import "./lib/BasicToken.sol";
 
contract WorldCupCryptoBet {    
    using SafeMath for uint256;

...



In header of contract i use SafeMath for operation on uint256. In order to do so I need to import basic operations library containing this type.

...
 mapping (uint8 => mapping (uint8 => mapping (address => uint256))) public bet;
 mapping (uint8 => mapping (uint8 => uint256 )) public ratio;
 mapping (uint8 => uint256 ) public total;
 mapping (uint8 => uint8) public matchResult;

 string public constant name = "WorldCupCryptoBet"; 
 address public owner_;
 uint8 activeMatch = 0;
 uint256 multiplier = 1;
...


bet - a table with a list of football matches and bets for each network wallet (matchNr, result, wallet) = bet in wei
ratio - a table ratio of bets made per match (1-left team win, 2 - draw, 3 - right team win)
total - a table containing sum of bets per match
matchResult - a table results of matches


...
 constructor() public { 
        owner_ = msg.sender;  
        uint256 decimal = uint256(10) ** 18;
        multiplier = decimal.mul(100000000);
    }   
...



Constructor in contract save owner of contract and multiplier to calculate correct value to withdraw

...
modifier onlyOwner() {
        require(msg.sender == owner_);
        _;
    }
...



modifier to run functions only by the contract owner

...
function Bet(uint8 matchNr, uint8 result) public payable {
        require(matchNr > activeMatch);        
        bet[matchNr][result][msg.sender] = msg.value;
        ratio[matchNr][result] += msg.value;
        total[matchNr] += msg.value;
    }
...



function to submit the bet, by sending the parameters in the transaction (match number, match result (1-3)
match no. - in the range (1-64), others will be bet on, but will not be scored so that you will not be able to withdraw from the contract
match result - in the range (1-3), 1 - win the team from the left, 2 - draw, 3 - win the team from the right

...
function nextMach(uint8 matchNr) public onlyOwner{
        activeMatch = matchNr;        
    }
...



function for setting available games, sets the number of the match that can still be bet

...
function setResoultMatch(uint8 matchNr, uint8 result) public onlyOwner{
        matchResult[matchNr] = result;       
    }
...



function sets the result of the match, performed only by the contract owner, as the parameter we pass the match number and result

...
function withdraw(uint8 matchNr) public {
        require(matchResult[matchNr] > 0);
        uint8 result = matchResult[matchNr];
        require(bet[matchNr][result][msg.sender] > 0);

        uint256 ratioVal = bet[matchNr][result][msg.sender].mul(multiplier);
        ratioVal = ratioVal.div(ratio[matchNr][result]);

        uint256 withdrawVal = total[matchNr].mul(ratioVal);
        uint256 valueToWithdraw = withdrawVal.div(multiplier);

        msg.sender.transfer(valueToWithdraw);        
    }
}


payout function as the match was finished - we can withdraw proportional winnings for those who called contract with winning bet


how to use contract

I deployed contract on robsten network
https://ropsten.etherscan.io/address/0xa0053ac096902d2e191bb03ac8b46ae45a25ae27

Use by metamask:
in metamask click send

then transaction data add function data with parameters for each function there is other data

Function list (owner only):

  • nextMatch - 0xc0f477820000000000000000000000000000000000000000000000000000000000000001
    • 0xc0f47782 - function number
    • 0000000000000000000000000000000000000000000000000000000000000001 - match number in hex

  • setResultMatch - 0xea2a40e400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001
    • 0xea2a40e4 - function number
    • 0000000000000000000000000000000000000000000000000000000000000001 - match number in hex
    • 0000000000000000000000000000000000000000000000000000000000000001 - result



other function list:

  • Bet - 0x703d45a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001
    • 0x703d45a- function number
    • 0000000000000000000000000000000000000000000000000000000000000001 - match number in hex
    • 0000000000000000000000000000000000000000000000000000000000000001 - result

  • withdraw- 0xc6ab5d900000000000000000000000000000000000000000000000000000000000000002
    • 0xc6ab5d9- function number
    • 0000000000000000000000000000000000000000000000000000000000000001 - match number in hex

If you have some question feel free to send me email [email protected]

Sort:  

Congratulations @sebek584! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

SteemitBoard - Witness Update
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.27
TRX 0.12
JST 0.031
BTC 61785.67
ETH 2891.86
USDT 1.00
SBD 3.54