# AbiItem.getSelector

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

Useful for computing function selectors for calldata.

## Imports

:::code-group
```ts [Named]
import { AbiItem } from 'ox'
```

```ts [Entrypoint]
import * as AbiItem from 'ox/AbiItem'
```
:::

## Examples

```ts twoslash
import { AbiItem } from 'ox'

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

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

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

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

```ts twoslash
import { AbiItem } from 'ox'

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
```

**Source:** [src/core/AbiItem.ts](https://github.com/wevm/ox/blob/main/src/core/AbiItem.ts#L805)

## Parameters

### abi

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

### name

* **Type:** `name`

## Return Type

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

`Hex.Hex`
