4/5
_Follow along with this video:_ --- ### Resetting the Player Array Continuing from where we left in the last lesson. We've picked the winner, we've opened the lottery and ... what do we do with the players already in the array? They've had their chance to win and they didn't. We add the following line inside the `fulfillRandomWords` function: ```solidity s_players = new address payable[](0); ``` This initializes a new empty array over the existing array, which is another way of saying **we wipe out the existing array**. Additionally, given that we are starting up a fresh raffle, we also need to bring the `s_lastTimeStamp` to the present time. ```solidity s_lastTimeStamp = block.timestamp; ``` The last thing we need to do is to emit an event that logs the fact that we picked a winner. Put this in your events section: `event PickedWinner(address winner);`. And emit it as the last line of the `fulfillRandomWords` function: `emit PickedWinner(winner);`. Run a `forge build` to make sure everything compiles. Great job!
A state-management guide to Resetting Raffle State for the Next Round - Discover the gas-efficient way to clear the players array in Solidity using `new address payable[](0)`. Properly reset raffle state, timestamp, and emit winner events to ensure a clean start for the next round.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Foundryup, Foundry Forge, and Anvil
Blockchain Oracles
How to create local Blockchain testnets
How to verify a smart contract
How to write and run smart contract tests
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Last updated on May 27, 2025
Solidity Developer
Foundry FundamentalsDuration: 2h 55min
Duration: 2h 56min
Duration: 26min
Duration: 5h 22min
Course Overview
About the course
Foundryup, Foundry Forge, and Anvil
Blockchain Oracles
How to create local Blockchain testnets
How to verify a smart contract
How to write and run smart contract tests
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Last updated on May 27, 2025