How to determine if ethereum address is an ERC20 token contract?

If you only get the ethereum address from the input, is there anyway to see if it is ERC20 compliant?

+3


source to share


1 answer


There are many possible ways to achieve this. One possible quick and dirty solution is to check if the ERC20 function is present on the contract address by calling the following:

eth.call({to:contractAddress, data:web3.sha3("balanceOf(address)")})

      



Non-ERC20 will return the hexadecimal response 'null' 0x

, whereas ERC20 will give you 32 bytes uint

, in this case 0, but if you specify an address in the data then it will give you the actual token balance for that address.

This is not a guaranteed way to define an ERC20 contract as other contracts may bill the same feature, however it is a quick and easy check. You can add additional calls to totalSupply()

, etc. For additional confirmation.

0


source







All Articles