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?
Regards,
Harish
Only payable functions receives eth.
"Selfdestruct" is indirect way of sending eth to an address without consent.
2 Likes
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: https://stackoverflow.com/questions/66819737/is-there-a-callback-function-that-is-triggered-on-transferfrom
2 Likes