How to detect if an ethereum address is an ERC20 token contract (2024)

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

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

A non-ERC20 will return a 'null'0xhex response whereas an ERC20 will give you a 32byteuint, in this case 0 but if you provide an address in the data then it will give you the actual token balance for that address.

This is not a guaranteed way of determining a contract is ERC20 since other contracts may expose the same function, however it is a quick and easy check. You could add additional calls ontotalSupply()etc. for more confirmation.

Hope this helps!

To know more, Enroll withBlockchain trainingonline today.

Thank You!!

How to detect if an ethereum address is an ERC20 token contract (2024)
Top Articles
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 5890

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.