Fallback and Receive Function

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?

I asked a similar question here. It seems that since 0.8.0, if no receive function is implemented, ethers sent to the contract would be rejected by default.

1 Like

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

1 Like

I think that is possible the solution:

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

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

1 Like

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/

Thanks for your reply

1 Like