Repository navigation
Add erc165Abi (ERC-165 supportsInterface) to the built-in ABIs
#5668
Unanswered
mortezashojaei
asked this question in
Idea / Feature Request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
ERC-165
supportsInterface(bytes4)is the standard way to find out what kind of contract an address is (ERC-721 vs ERC-1155, a receiver hook, an ERC-7984 token, and so on). Viem shipserc20Abi,erc721Abi,erc1155Abianderc4626Abi, but it has no standalone ERC-165 ABI. Since #5650,erc721Abianderc1155AbiincludesupportsInterface. Probing an address of unknown type witherc721Abireads oddly, though, and most projects redeclare the one-function ABI instead.Downstream evidence (observed in public code)
Each of these declares its own
supportsInterfaceABI and uses it with Viem'sreadContract,multicallorgetContract:customTestnet.ts#L52-L63: spreadserc721Abiwith a hand-writtensupportsInterfaceto detect ERC-721/ERC-1155 contracts.domain/erc20.ts#L121-L129:erc165Abiused next to Viem'serc20Abito make sure a token does not claim the ERC-721/ERC-1155 interfaces (usage).erc165.abi.ts#L4-L12: the ABI is generated fromIERC165.soland used for ERC-7984/ERC-1363 checks (usage).abi/erc165.ts#L8-L16nft-rpc-strategy.ts#L5-L35: uses Viem'serc721Abi, but a localerc165Abito classify NFTs.receivers.ts#L3-L28: checks ERC-721/ERC-1155 receiver interfaces.tools.ts#L33-L36A GitHub code search for
erc165Abiin TypeScript returns roughly 40 more repositories that redeclare the same ABI.Proposed API
Add
erc165Abitosrc/constants/abis.tsand export it fromviem, next to the other token ABIs:The entry is identical to the
supportsInterfaceitem already inerc721Abi/erc1155Abi, so it encodes to the same selector (0x01ffc9a7).Compatibility / maintenance
This adds one export with no new dependencies or behavior changes. The function is fixed by a final EIP, so there is little maintenance burden. Tree-shaken imports are unaffected;
import *grows by about 15 B gzip.Related: #3752 asks for interface-ID constants. That is a separate, larger design question and is not part of this proposal.
Feasibility
I ran a local proof against Ethereum mainnet with
multicall/readContract. BAYC reportserc165/erc721 = true, erc1155 = false; the ENS NameWrapper reportserc165/erc1155 = true, erc721 = false; USDC (no ERC-165) reverts and is reported as a failure underallowFailure: true.tscinfersbooleanand rejects unknown function names.PR to follow. (Prepared with help from an AI coding assistant; I reviewed the evidence and the results.)
All reactions