# AbiError.fromAbi

Extracts an [`AbiError.AbiError`](/api/AbiError/types#abierror) from an [`Abi.Abi`](/api/Abi/types#abi) given a name and optional arguments.

## Imports

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

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

## Examples

### Extracting by Name

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

```ts twoslash
import { Abi, AbiError } from 'ox'

const abi = Abi.from([
  'function foo()',
  'error BadSignatureV(uint8 v)',
  'function bar(string a) returns (uint256 x)'
])

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

### Extracting by Selector

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

```ts twoslash
import { Abi, AbiError } from 'ox'

const abi = Abi.from([
  'function foo()',
  'error BadSignatureV(uint8 v)',
  'function bar(string a) returns (uint256 x)'
])
const item = AbiError.fromAbi(abi, '0x095ea7b3') // [!code focus]
//    ^?
```

:::note
Extracting via a hex selector is useful when extracting an ABI Error from JSON-RPC error data.
:::

## Definition

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

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

## 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:** `AbiItem.fromAbi.Options<abi, name, args, AbiItem.internal.ExtractArgs<abi, name>>`
* **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>`
