How to assure a contract address is ERC20 compliant?

I’m building some contracts that interact with ERC20’s, but these ERC20’s are specified by some of the users and used by others.

How do I assure that the contract addresses supplied are ERC20 compliant?

1 Like

Hi @realisation,

You can check if an address is a contract: Address isContract

You can use SafeERC20 to wrap ERC20 operations to revert on failure.

You could try calling some of the IERC20 functions.

I am not sure if there is anything else you can do to ensure that contracts are ERC20 compliant, perhaps someone in the community can add to this.

There is nothing you can do to detect whether the contract addresses supplied are ERC20 compliant. As @abcoathup said, you can check that the address is a contract using isContract, and you can additionally call the balanceOf function, but this should only be meant to protect against accidents.

Your contract has to be tolerant to receiving non-compliant contracts. You should be careful, for example, that your contract does not lose people’s funds if it finds intself interacting with a non-ERC20 contract.


Hi @realisation,

Did the replies answer your question? Do you have further questions?

1 Like