> **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.fromAbi

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

Extracts an [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem) from an [`Abi.Abi`](/docs/utilities/abi/types#abi) given a name and optional arguments.

## Imports

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

## Examples

ABI Items can be extracted by their name using the `name` option:

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

const abi = Abi.from([
  'function foo()',
  'event Transfer(address owner, address to, uint256 tokenId)',
  'function bar(string a) returns (uint256 x)'
])

const item = AbiItem.fromAbi(abi, 'Transfer') // [!code focus]
//    ^?
```

### Extracting by Selector

ABI Items can be extract by their selector when [`Hex.Hex`](/docs/utilities/hex/types#hex) is provided to `name`.

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

const abi = Abi.from([
  'function foo()',
  'event Transfer(address owner, address to, uint256 tokenId)',
  'function bar(string a) returns (uint256 x)'
])
const item = AbiItem.fromAbi(abi, '0x095ea7b3') // [!code focus]
//    ^?
```

:::note
Extracting via a hex selector is useful when extracting an ABI Item from an `eth_call` RPC response, a Transaction `input`, or from Event Log `topics`.
:::

## Definition

```ts
function fromAbi<abi, name, args, allNames>(
  abi: abi | Abi.Abi | readonly unknown[],
  name: Hex.Hex | (name extends allNames ? name : never),
  options?: fromAbi.Options<abi, name, args>,
): fromAbi.ReturnType<abi, name, args>
```

## Parameters

### abi

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

The ABI to extract from.

### name

* **Type:** `Hex.Hex | (name extends allNames ? name : never)`

The name (or selector) of the ABI item to extract.

### options

* **Type:** `fromAbi.Options<abi, name, args>`
* **Optional**

Extraction options.

#### options.args

* **Type:** `allArgs | (Widen & (args extends allArgs ? unknown : never))`
* **Optional**

#### options.prepare

* **Type:** `boolean`
* **Optional**

Whether or not to prepare the extracted item (optimization for encoding performance).
When `true`, the `hash` property is computed and included in the returned value.

## Return Type

The ABI item.

`fromAbi.ReturnType<abi, name, args>`
