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

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

Parses an arbitrary **JSON ABI Item** or **Human Readable ABI Item** into a typed [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem).

## Imports

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

## Examples

### JSON ABIs

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

const abiItem = AbiItem.from({
  type: 'function',
  name: 'approve',
  stateMutability: 'nonpayable',
  inputs: [
    {
      name: 'spender',
      type: 'address'
    },
    {
      name: 'amount',
      type: 'uint256'
    }
  ],
  outputs: [{ type: 'bool' }]
})

abiItem
//^?
```

### Human Readable ABIs

A Human Readable ABI can be parsed into a typed ABI object:

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

const abiItem = AbiItem.from(
  'function approve(address spender, uint256 amount) returns (bool)' // [!code hl]
)

abiItem
//^?
```

It is possible to specify `struct`s along with your definitions:

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

const abiItem = AbiItem.from([
  'struct Foo { address spender; uint256 amount; }', // [!code hl]
  'function approve(Foo foo) returns (bool)'
])

abiItem
//^?
```

## Definition

```ts
function from<abiItem>(
  abiItem: (abiItem | AbiItem | string | readonly string[]) & ((abiItem extends string ? internal.Signature<abiItem> : never) | (abiItem extends readonly string[] ? internal.Signatures<abiItem> : never) | AbiItem),
  options?: from.Options,
): from.ReturnType<abiItem>
```

## Parameters

### abiItem

* **Type:** `(abiItem | AbiItem | string | readonly string[]) & ((abiItem extends string ? internal.Signature<abiItem> : never) | (abiItem extends readonly string[] ? internal.Signatures<abiItem> : never) | AbiItem)`

The ABI Item to parse.

### options

* **Type:** `from.Options`
* **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 typed ABI Item.

`from.ReturnType<abiItem>`
