In the previous recipe, we learned how to create a basic decentralized token and the procedure to record a bet. A lottery is more interesting when there is a prize involved. The logic for selecting a winner can be something like verifying the guess against some future block hash or number. We can also add a feature to decide the winning amount based on how accurate the prediction was.
In this recipe, you will learn how to select a winner based on logic in the smart contract. You will also learn how to calculate the winning amount and transfer it to the player.