# AbiEvent.fromAbi

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

## Imports

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

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

## Examples

### Extracting by Name

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

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

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

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

### Extracting by Selector

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

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

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

:::note
Extracting via a hex selector is useful when extracting an ABI Event from the first topic of a Log.
:::

## 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>>,
): AbiItem.fromAbi.ReturnType<abi, name, args, AbiEvent>
```

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

## 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.

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