Placing Bets
The battleWager function is the primary function used to place bets on the outcome of a Pokémon battle. This function checks the current state of the contract to ensure that betting is open, verifies
Function Breakdown
The function first checks if the state of the contract is
Open
. If not, it reverts the transaction.It then checks if the prediction is either 0 or 1, and if the bet amount is greater than 0. If either of these checks fail, the function reverts the transaction.
The function then calculates the amount to be bet, which is the submitted amount minus the contract's fee.
The
transferFrom
function of the PBetsToken contract is called, which transfers the bet amount from the user to the contract.The details of the bet are then stored in the contract's state variables.
Finally, a
BetPlaced
event is emitted, with the user's address, their prediction, the bet amount, and the current version of the contract.
Last updated