Replies: 2 comments 2 replies
-
As far I know, this is not possible using ethers.js. Some options are to use block explorers' API (if the contract was verified) or use Panoramix smart-contract decompiler (it will only get the partial ABI): |
Beta Was this translation helpful? Give feedback.
-
There is no way to do this, as EVM is turing complete, a contract could always be designed in such a way, that no matter what your method of detection is, there could be either false positives or false negatives. If this is just for the purpose of double checking in a UI, it might be ok to just use the tests you suggested, keeping in mind that ERC-721 would also pass a lot of ERC-20 checks. If you have a hard requirement that only ERC-20 contracts are used, you might need some sort of curated whitelist. With proxy contracts or Wisps, what was an ERC-20 token today could be something else tomorrow. I’m curious… Do modern ERC-20 contracts implement ERC-165? That might be one method to additionally check, but I think ERC-721 would still pass the same tests. |
Beta Was this translation helpful? Give feedback.
-
Hi Richard, @ricmoo
User enters an ethereum address in my front-end form and I should detect if it's ERC20 or not...
1 . Does ethers.js have anything like this ?
decimals(), name(), symbol()
functions. and if they don't get failed, then it means it's ERC20. problem is that those functions are optional on ERC20... So, sometimes token address might be ERC20, but we will still detect that it's not ERC20. What could be the better way of detecting ?The only way I can think of now is calling
totalSupply
andbalanceOf
. Problem is non-ERC20 can have these functions too and that's where I fail...Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions