ERCs

ERC-165 — Standard Interface Detection

eips.ethereum.org/EIPS/eip-165

A contract declares which interfaces it supports via supportsInterface(bytes4) — returning true for interface IDs it implements. The interface ID is the XOR of the function selectors.

import { eip155_1 } from "@ethernauta/chain/eip155-1";
import { AddressSchema, Bytes4Schema } from "@ethernauta/core";
import { supportsInterface } from "@ethernauta/erc/165";
import { eth_call } from "@ethernauta/eth";
import { contract, create_reader, encode_chain_id, http } from "@ethernauta/transport";
import { parse } from "valibot";

const CHAIN_ID = encode_chain_id({ namespace: "eip155", reference: eip155_1.chainId });
const reader = create_reader([
  { chainId: CHAIN_ID, transports: [http("https://ethereum-rpc.publicnode.com")] },
]);
const nft_address = parse(AddressSchema, "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D");

const callable = supportsInterface({ interfaceId: parse(Bytes4Schema, "0x80ac58cd") })(
  contract({ chain_id: CHAIN_ID, to: nft_address }),
);
const result_bytes = await eth_call([{ to: callable.to, input: callable.data }])(reader({ chain_id: CHAIN_ID }));
const ok = callable.decode(result_bytes);
// true → contract implements ERC-721

Surface

MethodShapePurpose
supportsInterface({ interface_id })Callable<boolean>Per-interface detection.

Common interface IDs

IDStandard
0x80ac58cdERC-721
0x5b5e139fERC-721 Metadata
0x780e9d63ERC-721 Enumerable
0xd9b67a26ERC-1155
0x0e89341cERC-1155 Metadata URI
0x2a55205aERC-2981 (royalties)

See also