DEV Community

Cover image for Casino game SmartContract deployed on XinFin XDC Network
MahaLakshmi Perumal
MahaLakshmi Perumal

Posted on

Casino game SmartContract deployed on XinFin XDC Network

Deployed a Casino smartcontract on XinFin XDC Network, and it is very easy and cheap to deploy on XinFin Network. The stable network where the new generation Developers should deploy their #DAPPS and #SmartContracts.

Check the Solidity Contract for Casino:

pragma solidity ^0.4.18;
contract CasinoRoulette {
enum BetType { Color, Number }
struct Bet {
address user;
uint amount;
BetType betType;
uint block;
// @prop choice: interpretation is based on BetType
// BetType.Color: 0=black, 1=red
// BetType.Number: -1=00, 0-36 for individual numbers
int choice;
}
uint public constant NUM_POCKETS = 38;
// RED_NUMBERS and BLACK_NUMBERS are constant, but
// Solidity doesn't support array constants yet so
// we use storage arrays instead
uint8[18] public RED_NUMBERS = [
1, 3, 5, 7, 9, 12,
14, 16, 18, 19, 21, 23,
25, 27, 30, 32, 34, 36
];
uint8[18] public BLACK_NUMBERS = [
2, 4, 6, 8, 10, 11,
13, 15, 17, 20, 22, 24,
26, 28, 29, 31, 33, 35
];
// maps wheel numbers to colors
mapping(int => int) public COLORS;
address public owner;
uint public counter = 0;
mapping(uint => Bet) public bets;
event BetPlaced(address user, uint amount, BetType betType, uint block, int choice);
event Spin(uint id, int landed);
function CasinoRoulette () public {
owner = msg.sender;
for (uint i=0; i < 18; i++) {
COLORS[RED_NUMBERS[i]] = 1;
}
}
function wager (BetType betType, int choice) payable public {
require(msg.value > 0);
if (betType == BetType.Color)
require(choice == 0 || choice == 1);
else
require(choice >= -1 && choice <= 36);
counter++;
bets[counter] = Bet(msg.sender, msg.value, betType, block.number + 3, choice);
BetPlaced(msg.sender, msg.value, betType, block.number + 3, choice);
}
function spin (uint id) public {
Bet storage bet = bets[id];
require(msg.sender == bet.user);
require(block.number >= bet.block);
require(block.number <= bet.block + 255);
bytes32 random = keccak256(block.blockhash(bet.block), id);
int landed = int(uint(random) % NUM_POCKETS) - 1;
if (bet.betType == BetType.Color) {
if (landed > 0 && COLORS[landed] == bet.choice)
msg.sender.transfer(bet.amount * 2);
}
else if (bet.betType == BetType.Number) {
if (landed == bet.choice)
msg.sender.transfer(bet.amount * 35);
}
delete bets[id];
Spin(id, landed);
}
function fund () public payable {}
function kill () public {
require(msg.sender == owner);
selfdestruct(owner);
}
}

Discussion (2)

Collapse
megaboyyyy profile image
Asema Uspova

Hi , I want to tell you that at this point in time there is no need to create a new one , just choose one good one , like mycasinosguide.com/ .
I made a little mistake on this site quite a lot of different casinos and they are all good. You can play at each and win. Also listed on the site are the bonuses that are given when you register. I advise you to register through the links from this site. That way, the bonuses will be as big as possible.

Collapse
cermitio profile image
Cermitio

Finally, progress is reaching even such areas as the online casino market. To tell the truth, I tried to play on different bonus currating platforms and had different experiences. Therefore, I saw that even among the sites on 777casino.co.uk/online-casinos, you will be able to find those platforms that work on outdated principles and methods, which leads to poor security. But some are equiped with top-notch tech solutions so you can play with no worries.