Solidity - How to prevent receiving ETH or Tokens directly to smart contract?

Hello Guys,

I would like to prevent users send ETH or tokens directly to the smart contract. I am creating a smart contract where the ERC20 token transfer to the smart contract only through the function present in the smart contract. However, I don't want users sending ETH or ERC20 directly to the smart contract.

How can I achieve this?


Only payable functions receives eth.
"Selfdestruct" is indirect way of sending eth to an address without consent.


short answer: you can't.

For ether you could try to define a fallback function that reverts any reception of Ether, but as @Jagadish_K pointed out, this can be circumvented by using a selfdestruct function.

For ERC20-tokens, see here: