Withdraw function

Hello guys,
I am completely new to blockchain dev, and I am practicing a lottery contract where people buy ticket and every 24h one address is randomly chosen.
I canot figure it out an withdraw function from an adress(lottery pool) to winner address.

1 Like

You can create a safe transfer function of ether in lottery pool to winners address

2 Likes

Can you share the lottery contract? You can use chainlink to randomly select a winner.

you can use interfaces like
interface IERC20 { function transfer(sender, amount) external; }

this is not on point but you get it. instead of my weird transfer function you use the transfer function of the token
then you put something like this in the main contract:

IERC20 token = IERC20(token address)
winnings = 10e18
function withdraw() public  {
token.transfer(winnings, msg.sender)
}

should look something like that. I think you got the concept. create an interface to use the functions of another contract (the token to be paid out with) create a variable with the datatype of your interface and use the importet function (transfer) in the withdraw function.

1 Like