# Fallback and Receive Function

**URL:** <https://forum.openzeppelin.com/t/fallback-and-receive-function/17325>\
**Category:** Security\
**Created:** [October 21, 2021, 10:49am UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325 "2021-10-21T10:49:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cainuriel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/cainuriel/32/5410_2.png) [@Cainuriel](https://forum.openzeppelin.com/u/Cainuriel)\
**Post date:** [October 21, 2021, 10:49am UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325/1 "2021-10-21T10:49:57Z")

</div>

Hello Zeppelines !!

I know that the receive and fallback functions are called when some payment is made, **receive function** , or the contract is called for some circumstancem **fallback function**.

My question is this.  
If I don't want Ethers to be sent to my contract directly, would not using these functions be enough?  
Or could it generate some kind of error message in the fallback for example announcing the direct transfer lock in my contract?

---

<div class="post-metadata">

**Author:** ![maxareo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maxareo/32/11606_2.png) [@maxareo](https://forum.openzeppelin.com/u/maxareo)\
**Post date:** [October 21, 2021, 4:49pm UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325/2 "2021-10-21T16:49:10Z")

</div>

I asked a similar question [here](https://forum.openzeppelin.com/t/a-basic-nonreceivable-contract-template/11727). It seems that since 0.8.0, if no `receive` function is implemented, ethers sent to the contract would be rejected by default.

---

<div class="post-metadata">

**Author:** ![Cainuriel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/cainuriel/32/5410_2.png) [@Cainuriel](https://forum.openzeppelin.com/u/Cainuriel)\
**Post date:** [October 21, 2021, 6:59pm UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325/3 "2021-10-21T18:59:21Z")

</div>

Yes, I had heard something. But if I am using versions like v6.12, how should I reject the transfer?

---

<div class="post-metadata">

**Author:** ![Cainuriel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/cainuriel/32/5410_2.png) [@Cainuriel](https://forum.openzeppelin.com/u/Cainuriel)\
**Post date:** [October 21, 2021, 11:08pm UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325/4 "2021-10-21T23:08:57Z")

</div>

I think that is possible the solution:

```auto
  /**
   * Prevent payments to the contract
   */
  fallback () external payable {
    revert();
  }
}

```

---

<div class="post-metadata">

**Author:** ![maxareo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maxareo/32/11606_2.png) [@maxareo](https://forum.openzeppelin.com/u/maxareo)\
**Post date:** [October 21, 2021, 11:27pm UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325/5 "2021-10-21T23:27:20Z")

</div>

exactly. I wrote a non-receivable contract in that thread.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [October 22, 2021, 1:57am UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325/6 "2021-10-22T01:57:02Z")

</div>

These two keywords were added after version 0.6, I think you can have a look at this tutorial about these new features: [https://blog.soliditylang.org/2020/03/26/fallback-receive-split/](https://blog.soliditylang.org/2020/03/26/fallback-receive-split/)

---

<div class="post-metadata">

**Author:** ![Cainuriel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/cainuriel/32/5410_2.png) [@Cainuriel](https://forum.openzeppelin.com/u/Cainuriel)\
**Post date:** [October 22, 2021, 11:40am UTC](https://forum.openzeppelin.com/t/fallback-and-receive-function/17325/7 "2021-10-22T11:40:17Z")

</div>

Thanks for your reply
