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?
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?
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?
Hi @realisation,
I thought the Online ERC20 Contract Verifier might be of interest:
I found this as well: https://github.com/ethereum/EIPs/issues/2290
An official ERC20 factory
You can use tools like isiterc20.xyz to check if a smart contract address implements the ERC-20 interface. Just enter the contract address and select the network to verify.