Explain solidity>payable functions

Adding Stakes with ETH

Let's make the game more interesting by adding ETH stakes. Players will bet ETH, and the winner takes the pot!

The payable Keyword:

To receive ETH in a function, add the payable keyword.

function startGame(address _opponent) public payable { ... }



msg.value:

msg.value tells you how much ETH was sent with the function call.

It's measured in wei (1 ETH = 10^18 wei).



Storing the Stake:

Add a state variable: uint public stake;

In startGame, save the amount: stake = msg.value;



Resetting the Board:

When a new game starts, we need to clear the old board.

Use a for loop to reset all cells: for (uint i = 0; i < 9; i++) { board[i] = Cell.Empty; }



Update startGame to accept ETH stakes and reset the board.

Add ETH stakes to the game
0%
Requirements:
Declares uint public stake
startGame is payable
Stores msg.value in stake
Clears board with for loop
Board reset is in startGame