solidity - How to detect if an ethereum address is an ERC20 token contract? -


if ethereum address input, there anyway find out whether match erc20?

there many possible ways achieve this. 1 possible quick , dirty solution check if erc20 function exists on contract address calling following:

eth.call({to:contractaddress, data:web3.sha3("balanceof(address)")}) 

a non-erc20 return 'null' 0x hex response whereas erc20 give 32byte uint, in case 0 if provide address in data give actual token balance address.

this not guaranteed way of determining contract erc20 since other contracts may expose same function, quick , easy check. add additional calls on totalsupply() etc. more confirmation.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -