Mc01 / crypto-casino-games

🎰 Crypto Casino Games (CCG)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crypto Games

Smart contracts for gambling on Ethereum

Setup

Run Docker:

docker-compose up -d

Documentation

Code is heavily documented to be viewed on Etherscan

For documentation please refer to functions in /contracts:

  • Token.transferAndCall()
  • Game.play()
  • <individual_game_contract>.handleSuccess()

Where individual_game_contract can be Dice contract for example

Integration

Following functions are externally callable

Dashboard:

  • Dashboard.lastGameId() -> int
  • Dashboard.gameIds(gameId: int) -> address
  • Dashboard.games(game: address) -> (int, address, bool)

Token:

  • Token.transferAndCall(tokens: int, game: address, context: bytes[])

Example of transferAndCall for scenario:

  • stake: 100 tokens
  • game address: 0x123
  • context -> risk: 1111
Token.transferAndCall(
    100, 
    0x123, 
    [web3.bytes(1111)]
)

How integration can be approached? Note: Following examples are for Web3 JavaScript client

  • integrate Web3 with client
const Web3 = require('web3')
  • configure for Rinkeby testnet network
const web3 = new Web3(
    new Web3.providers.HttpProvider(infuraUrl)
)
  • load private keys from securely stored credentials
const account = web3.eth.accounts.privateKeyToAccount(privateKey)
  • integrate ABI interfaces from extracted ABIs in abi directory
const abi = JSON.parse(
    fs.readFileSync('abi/Contract.json')
)
  • instantiate contract
const contract = web3.eth.Contract(abi).at(address)
  • start integration from Dashboard's methods
  • -> they are call functions, means they are read-only
  • -> they returns simple and complex values
await DashboardContract.lastGameId().call({
    from: account
})
  • implement transferAndCall for Token
  • -> this method is transaction function, means write-only
  • -> it requires to be owner of staked tokens
  • -> it accepts address of
  • -> additionally Web3 coded bytes are passed in context
await TokenContract.transferAndCall(
    tokens,
    gameAddress,
    context,
    {
        from: account
    }
)
  • add creation of new Game contract
new web3.eth.Contract(abi, {
    from: account
})

About

🎰 Crypto Casino Games (CCG)


Languages

Language:Solidity 75.6%Language:JavaScript 22.1%Language:Dockerfile 1.7%Language:Makefile 0.6%