Protecting users from wrong transfer

This is just a morning thought

I have added this hook to my contract

function _beforeTokenTransfer(address from,address to,uint256 amount) internal virtual override {
         require(to != address (this) , "Error: sending the token to its contract");

in case the contract will be renounced , I feel this should be by default isn't ? do you think there is better way to protect users from sending the contract token to the contract address by error ?

1 Like

there are legitimate reason to sometimes send tokens to the contract address itself.


Can you please give few examples ?

1 Like

Some examples where it would be normal/part of the process to send tokens to the contract itself:

  • Wrapped token: you would need to send tokens to the contract to be able to mint wrapped tokens.
  • Liquidity pool: Some contracts hold one asset to lend another, so users would need to transfer their tokens to a contract.
  • tokens can be sent to the contract to meet certain threshold before some even can happen.

No need for the token contract address to be outrightly prevented from recieving it token

1 Like