Skip to content

feat: add erc165Abi - #5669

Closed
mortezashojaei wants to merge 1 commit into
wevm:mainfrom
mortezashojaei:feat/erc165-abi
Closed

mortezashojaei wants to merge 1 commit into
wevm:mainfrom
mortezashojaei:feat/erc165-abi

Conversation

@mortezashojaei

Copy link
Copy Markdown
Contributor

Refs #5668

Why

Viem ships erc20Abi, erc721Abi, erc1155Abi and erc4626Abi, but no standalone ERC-165 ABI. Projects that need to find out what kind of contract an address is (ERC-721 vs ERC-1155, receiver hooks, ERC-7984 tokens, …) redeclare the one-function supportsInterface ABI next to Viem. Examples include RabbyHub/Rabby, tempoxyz/tempo-apps, zama-ai/sdk, PaulRBerg/prb-effect, 3loop/loop-decoder, Swader/rescuekit and NaniDAO/agentek, plus roughly 40 more repos from a code search. Permalinks are in #5668.

What

  • src/constants/abis.ts: adds erc165Abi with supportsInterface(bytes4 interfaceId) view returns (bool). The entry is identical to the supportsInterface item already in erc721Abi/erc1155Abi, and the TSDoc link follows the other token ABIs.
  • src/index.ts: exports it next to the other token ABIs.
  • src/constants/abis.test.ts and src/index.test.ts: update the existing exports abis and exports inline snapshots.
  • Patch changeset.

Usage

import { erc165Abi } from 'viem'

const isErc721 = await client.readContract({
  address,
  abi: erc165Abi,
  functionName: 'supportsInterface',
  args: ['0x80ac58cd'],
}) // boolean

Validation

  • SKIP_GLOBAL_SETUP=true pnpm test --run --update all --project core src/constants/abis.test.ts src/index.test.ts: 2 passed. The snapshot diff contains only the new entries.
  • tsc -p src/tsconfig.json --noEmit: passes.
  • biome check on the changed files: clean.
  • Bundle size: size-limit was not run locally. An esbuild minify+gzip of export * from 'viem' grows by 15 B.
  • I also ran a throwaway script (not included) against Ethereum mainnet:
    • multicall with allowFailure: true gives BAYC erc165/erc721 = true, erc1155 = false and the ENS NameWrapper erc165/erc1155 = true, erc721 = false. USDC (no ERC-165) returns failures.
    • readContract infers boolean.
    • encodeFunctionData output matches erc721Abi's supportsInterface.
    • tsc rejects unknown function names.

Compatibility

This adds one export and changes nothing else. There are no new dependencies, and tree-shaken imports are unaffected. Interface-ID constants (#3752) are out of scope.

AI assistance

I prepared this with help from an AI coding assistant (Claude Code). I reviewed the evidence, diff, and test results.

@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

@mortezashojaei is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 263d221

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jxom jxom mentioned this pull request Nov 25, 2026

jxom commented Nov 25, 2026

Copy link
Copy Markdown
Member

Thanks @mortezashojaei, this is a useful addition. I opened #5670 to carry it forward with your commit kept. It adds one small change: the output is declared as { type: "bool" } without name: '', so the entry matches the supportsInterface entry added to erc721Abi in #5650. Closing this in favor of #5670.

@jxom jxom closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants