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

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

Utilities & types for working with [ABI Items](https://docs.soliditylang.org/en/latest/abi-spec.html#json)

The `AbiItem` type is a super-type of:

* [`AbiConstructor`](/docs/utilities/abiconstructor)
* [`AbiFunction`](/docs/utilities/abifunction)
* [`AbiEvent`](/docs/utilities/abievent)
* [`AbiError`](/docs/utilities/abierror)

## Examples

Below are some examples demonstrating common usages of the `AbiItem` module:

* [Instantiating via JSON ABI](#instantiating-via-json-abi)

* [Instantiating via Human-Readable ABI Item](#instantiating-via-human-readable-abi-item)

* [Formatting ABI Items](#formatting-abi-items)

### Instantiating via JSON ABI

An `AbiItem` can be instantiated from a JSON ABI by using [`AbiItem.fromAbi`](/docs/utilities/abiitem/fromAbi):

```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]
//    ^?
```

### Instantiating via Human-Readable ABI Item

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)'
)

abiItem
//^?
```

### Formatting ABI Items

An `AbiItem` can be formatted into a human-readable ABI Item by using [`AbiItem.format`](/docs/utilities/abiitem/format):

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

const abiItem = AbiItem.from(
  'function approve(address spender, uint256 amount) returns (bool)'
)

const formatted = AbiItem.format(abiItem)
// @log: 'function approve(address spender, uint256 amount) returns (bool)'
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`AbiItem.format`](/docs/utilities/abiitem/format) | Formats an [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem) into a **Human Readable ABI Item**. |
| [`AbiItem.from`](/docs/utilities/abiitem/from) | Parses an arbitrary **JSON ABI Item** or **Human Readable ABI Item** into a typed [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem). |
| [`AbiItem.fromAbi`](/docs/utilities/abiitem/fromAbi) | Extracts an [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem) from an [`Abi.Abi`](/docs/utilities/abi/types#abi) given a name and optional arguments. |
| [`AbiItem.getSelector`](/docs/utilities/abiitem/getSelector) | Computes the [4-byte selector](https://solidity-by-example.org/function-selector/) for an [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem). |
| [`AbiItem.getSignature`](/docs/utilities/abiitem/getSignature) | Computes the stringified signature for a given [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem). |
| [`AbiItem.getSignatureHash`](/docs/utilities/abiitem/getSignatureHash) | Computes the signature hash for an [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem). |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`AbiItem.AmbiguityError`](/docs/utilities/abiitem/errors#abiitemambiguityerror) | Throws when ambiguous types are found on overloaded ABI items. |
| [`AbiItem.InvalidAbiItemError`](/docs/utilities/abiitem/errors#abiiteminvalidabiitemerror) |  |
| [`AbiItem.InvalidSelectorSizeError`](/docs/utilities/abiitem/errors#abiiteminvalidselectorsizeerror) | Throws when the selector size is invalid. |
| [`AbiItem.NotFoundError`](/docs/utilities/abiitem/errors#abiitemnotfounderror) | Throws when an ABI item is not found in the ABI. |
| [`AbiItem.UnknownSolidityTypeError`](/docs/utilities/abiitem/errors#abiitemunknownsoliditytypeerror) |  |
| [`AbiItem.UnknownTypeError`](/docs/utilities/abiitem/errors#abiitemunknowntypeerror) |  |

## Types

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitemabiitem) | Root type for an item on an [`Abi.Abi`](/docs/utilities/abi/types#abi). |
| [`AbiItem.ExtractNames`](/docs/utilities/abiitem/types#abiitemextractnames) |  |
| [`AbiItem.FromAbi`](/docs/utilities/abiitem/types#abiitemfromabi) | Extracts an [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem) item from an [`Abi.Abi`](/docs/utilities/abi/types#abi), given a name. |
| [`AbiItem.Name`](/docs/utilities/abiitem/types#abiitemname) | Extracts the names of all [`AbiItem.AbiItem`](/docs/utilities/abiitem/types#abiitem) items in an [`Abi.Abi`](/docs/utilities/abi/types#abi). |
