Skip to content

fix: add supportsInterface and correct tokenOfOwnerByIndex in erc721Abi - #5650

Merged
jxom merged 1 commit into
wevm:mainfrom
mortezashojaei:fix/erc721-abi-enumerable-erc165
Nov 23, 2026
Merged

jxom merged 1 commit into
wevm:mainfrom
mortezashojaei:fix/erc721-abi-enumerable-erc165

Conversation

@mortezashojaei

Copy link
Copy Markdown
Contributor

Refs #5649

Why

erc721Abi doesn't fully match ERC-721:

  • It declares ERC721Enumerable's tokenOfOwnerByIndex(address owner, uint256 index) as a second tokenByIndex overload. As a result, functionName: 'tokenOfOwnerByIndex' throws AbiFunctionNotFoundError, and tokenByIndex(owner, index) encodes selector 0xcb60f1bf, which reverts on real contracts. viem's own test fixture (test/src/abis.ts) already uses the correct name.
  • It doesn't include ERC-165 supportsInterface, which EIP-721 makes mandatory and which erc1155Abi already includes.

Public code works around both. Rabby ("viem's erc721Abi has no ERC-165 supportsInterface") and Kleros ("viem doesn't export this") extend or supplement the ABI by hand, and SIR-trading multicalls tokenOfOwnerByIndex with erc721Abi. Permalinks are in #5649.

What

  • src/constants/abis.ts: renames the (owner, index) overload to tokenOfOwnerByIndex and adds supportsInterface(bytes4) view returns (bool), keeping the existing alphabetical order. tokenByIndex(uint256) is unchanged.
  • src/constants/abis.test.ts: updates the existing exports abis inline snapshot.
  • Patch changeset.

Usage

import { erc721Abi } from 'viem'

const isErc721 = await client.readContract({ address, abi: erc721Abi, functionName: 'supportsInterface', args: ['0x80ac58cd'] })
const tokenId = await client.readContract({ address, abi: erc721Abi, functionName: 'tokenOfOwnerByIndex', args: [owner, 0n] })

Validation

  • pnpm test --update all --run src/constants/abis.test.ts: 1 passed. The snapshot diff contains only the two ABI entries.
  • tsc -p src/tsconfig.json --noEmit: passes.
  • biome check on the changed files: clean.
  • I ran a throwaway script (not included) against Ethereum mainnet's Uniswap V3 NonfungiblePositionManager, an ERC721Enumerable contract:
    • With the current ABI, tokenByIndex(owner, 0) reverts, and both tokenOfOwnerByIndex and supportsInterface throw AbiFunctionNotFoundError.
    • With this change, tokenOfOwnerByIndex(owner, 0) returns 5n, supportsInterface(0x80ac58cd) returns true, supportsInterface(0xd9b67a26) returns false, and tokenByIndex(0) still returns 1n.

Compatibility

supportsInterface is additive. The rename removes only the non-standard tokenByIndex(address,uint256) signature, which can't succeed against a standard ERC-721 contract, so I've treated it as a patch fix (like #3710).

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 23, 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 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f8afaa

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 merged commit 4079b5d into wevm:main Nov 23, 2026
26 of 35 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
This was referenced 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