# Withdraw function

**URL:** <https://forum.openzeppelin.com/t/withdraw-function/26096>\
**Category:** Smart Contracts\
**Created:** [March 13, 2022, 9:51am UTC](https://forum.openzeppelin.com/t/withdraw-function/26096 "2022-03-13T09:51:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwccrc](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@mwccrc](https://forum.openzeppelin.com/u/mwccrc)\
**Post date:** [March 13, 2022, 9:51am UTC](https://forum.openzeppelin.com/t/withdraw-function/26096/1 "2022-03-13T09:51:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![YummyDao](https://avatars.discourse-cdn.com/v4/letter/y/4af34b/32.png) [@YummyDao](https://forum.openzeppelin.com/u/YummyDao)\
**Post date:** [March 13, 2022, 10:12pm UTC](https://forum.openzeppelin.com/t/withdraw-function/26096/2 "2022-03-13T22:12:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arome](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@arome](https://forum.openzeppelin.com/u/arome)\
**Post date:** [March 17, 2022, 10:12am UTC](https://forum.openzeppelin.com/t/withdraw-function/26096/3 "2022-03-17T10:12:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Team\_X](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/team_x/32/10471_2.png) [@Team\_X](https://forum.openzeppelin.com/u/Team_X)\
**Post date:** [March 22, 2022, 3:37pm UTC](https://forum.openzeppelin.com/t/withdraw-function/26096/4 "2022-03-22T15:37:18Z")

</div>

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:

```auto
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.
