Framework
Last updated
Last updated
The technical flow on the Mega Casino platform for players using Chainlink-integrated chains (Mega Casino utilizes the Subscription method) occurs in two transactions and proceeds as follows:
Placed bet
A player calls the Place_Bet
function on any Game Contract to place a wager. The wager (bet token) is transferred to the corresponding Game Contract.
VRF Fee
An estimate of the VRF fee is charged upfront in the native token for standard gameplay.
VRF Refund
In the same transaction, a partial refund of the VRF fee is provided to the player if they initially overpaid for the VRF cost.
If the cost of the callback exceeds the initial estimation, Randomizer allows an additional refund during the next gameplay session on the same contract.
VRF Request
The VRF fee is sent to the Game Contract (or to the Randomizer VRF Contract), and the Game Contract (the consumer) calls the requestRandomNumber function on the VRFCoordinator contract. The VRFCoordinator then emits an event to indicate that a VRF callback is required.
The Mega Casino platform utilizes a Chainlink node that listens for randomness requests from the VRFCoordinator. The node generates randomness by mixing its private key with the blockhash of the request and calls the fulfillRandomNumber (callback VRF function) on the VRFCoordinator. If multiple requests are pending, the BatchVRFCoordinator is invoked to handle multiple fulfillments and forwards them to the VRFCoordinator. The Chainlink node waits for requestConfirmations (specified in blocks) before responding. For Mega Casino, we have set the number of blocks at 3 for the Mega ETH chain.
The VRFCoordinator then calls rawFulfillRandomNumber on the Game Contract.
The Game Contract determines the outcome and transfers the wager to the Diamond Contract (bankroll).
If the player wins or draws, the bankroll sends the payout to the player at the same time. If the player loses, no payout is issued, and the bankroll retains the wager.
The infrastructure of Mega Casino is non-custodial, ensuring that player funds are never at risk. If a VRF request fails or the bankroll is unable to process a payout, the transaction will either revert, or the wager will become stuck in the Game Contract. In such cases, the player can remove their bet using the refund function under Pending VRF Requests on their profile page.