I want my ERC20 contract to be transferred to EOA addresses only and some specific contract address only.

I don't want to lose my tokens by mistakenly transferring to a contract address that cannot handle ERC20 tokens.

How can I prevent my ERC20 contract to prevent the transfer of tokens to contract addresses?

2 Answers 2


You should modify the contract's transfer and approve functions to check if the target address is a contract address. If it is, revert the transaction.

You can check if an address is a contract address with:

function isContract(address _addr) private returns (bool isContract){
  uint32 size;
  assembly {
    size := extcodesize(_addr)
  return (size > 0);

(From https://ethereum.stackexchange.com/a/15642/31933)

Note that this makes any token transfers more expensive as the same check has to be performed every time a transfer/approve is made.


Include this line at the beginning of your ERC20 transfer function:

require (to != address(this));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.