> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# AbiItem.getSelector

:::info
`AbiItem.getSelector` is a re-export of ox's [`AbiItem.getSelector`](https://oxlib.sh/api/AbiItem/getSelector). Refer to the ox documentation for the full reference.
:::

Computes the [4-byte selector](https://solidity-by-example.org/function-selector/) for an [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem).

Useful for computing function selectors for calldata.

## Imports

```ts
import { AbiItem } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { AbiItem } from 'viem/utils'

const selector = AbiItem.getSelector(
  'function ownerOf(uint256 tokenId)'
)
// @log: '0x6352211e'
```

```ts twoslash
// @noErrors
import { Abi, AbiItem } from 'viem/utils'

const erc20Abi = Abi.from([...])

const selector = AbiItem.getSelector(erc20Abi, 'ownerOf')
// @log: '0x6352211e'
```

```ts twoslash
// @noErrors
import { AbiItem } from 'viem/utils'

const selector = AbiItem.getSelector({
  inputs: [{ type: 'uint256' }],
  name: 'ownerOf',
  outputs: [],
  stateMutability: 'view',
  type: 'function'
})
// @log: '0x6352211e'
```

## Definition

```ts
function getSelector<abi, name>(
  abi: abi | Abi.Abi | readonly unknown[],
  name: name,
): Hex.Hex
```

## Parameters

### abi

* **Type:** `abi | Abi.Abi | readonly unknown[]`

### name

* **Type:** `name`

## Return Type

The first 4 bytes of the [`Hash.keccak256`](/docs/utilities/hash/keccak256) hash of the function signature.

`Hex.Hex`
