> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# ERC-165 Interface Detection

> Calculate and check ERC-165 interface IDs

ERC-165 standard interface detection for smart contracts.

<Tip title="ERC Reference">
  Implements [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface detection mechanism.
</Tip>

## Overview

ERC-165 enables contracts to declare which interfaces they support. Interface IDs are computed by XORing function selectors, creating a unique 4-byte identifier for each interface.

## getInterfaceId

### `getInterfaceId(selectors: SelectorLike[]): InterfaceIdType`

Calculates ERC-165 interface ID by XORing function selectors.

**Parameters:**

* `selectors: SelectorLike[]` - Array of function selectors (4 bytes each)

**Returns:** `InterfaceIdType` - 4-byte interface ID

**Example:**

```typescript theme={null}
import { getInterfaceId } from '@tevm/voltaire/Abi/interface';

// Calculate ERC-20 interface ID
const erc20InterfaceId = getInterfaceId([
  '0x70a08231', // balanceOf(address)
  '0x095ea7b3', // approve(address,uint256)
  '0xa9059cbb', // transfer(address,uint256)
  '0xdd62ed3e', // allowance(address,address)
  '0x23b872dd', // transferFrom(address,address,uint256)
  '0x18160ddd', // totalSupply()
]);

console.log('0x' + Buffer.from(erc20InterfaceId).toString('hex'));
// '0x36372b07'
```

## Standard Interface IDs

### ERC165\_INTERFACE\_ID

```typescript theme={null}
const ERC165_INTERFACE_ID = '0x01ffc9a7'
```

Interface ID for `supportsInterface(bytes4)` function itself.

### ERC20\_INTERFACE\_ID

```typescript theme={null}
const ERC20_INTERFACE_ID = '0x36372b07'
```

Interface ID for ERC-20 token standard.

**Functions:**

* `balanceOf(address)`
* `transfer(address,uint256)`
* `approve(address,uint256)`
* `transferFrom(address,address,uint256)`
* `allowance(address,address)`
* `totalSupply()`

### ERC721\_INTERFACE\_ID

```typescript theme={null}
const ERC721_INTERFACE_ID = '0x80ac58cd'
```

Interface ID for ERC-721 NFT standard.

### ERC1155\_INTERFACE\_ID

```typescript theme={null}
const ERC1155_INTERFACE_ID = '0xd9b67a26'
```

Interface ID for ERC-1155 multi-token standard.

## Usage Patterns

### Check Interface Support

```typescript theme={null}
import { ERC20_INTERFACE_ID, ERC721_INTERFACE_ID } from '@tevm/voltaire/Abi/interface';

async function detectTokenStandard(contractAddress: string) {
  // Call supportsInterface(bytes4)
  const isErc20 = await contract.supportsInterface(ERC20_INTERFACE_ID);
  const isErc721 = await contract.supportsInterface(ERC721_INTERFACE_ID);

  if (isErc721) return 'ERC-721';
  if (isErc20) return 'ERC-20';
  return 'Unknown';
}
```

### Custom Interface

```typescript theme={null}
import { getInterfaceId } from '@tevm/voltaire/Abi/interface';
import { Selector } from '@tevm/voltaire/Selector';

// Define custom interface
const selectors = [
  Selector.fromSignature('myFunction(uint256)'),
  Selector.fromSignature('anotherFunction(address)')
];

const interfaceId = getInterfaceId(selectors);

// Implement in Solidity
// function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
//   return interfaceId == 0x... || super.supportsInterface(interfaceId);
// }
```

## Specification

**Defined in:** [src/primitives/Abi/interface/](https://github.com/evmts/voltaire/blob/main/src/primitives/Abi/interface/)

**See also:**

* [ERC-165 Specification](https://eips.ethereum.org/EIPS/eip-165)
* [Selector](/primitives/selector) - Function selector utilities
