DEV Community

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

Posted on

1 2

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);
}
}

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (3)

Collapse
 
mikeperez73 profile image
MikePerez73 • Edited

It is important to check the accreditation and reputation of an online casino or cryptocurrency exchange platform before trusting them with your funds. Look for reviews from other users and research their work history. bitcoininsider.org/article/211271/...

Collapse
 
jacquelinefrances profile image

The best choice for recommending a 안전놀이터 is Hitman, who insists on only major sites and major playgrounds. A safe park that has passed the best verification of Private Toto exists in Hitman. There are only a handful of toto sites that are perfect for those who dream of becoming a major toto site and a major safe playground. Toto betting site absolutely puts safety first.

Collapse
 
danielsinoca profile image
Daniel Sinoca

Great job, there will be time to get acquainted with our project!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay