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

# AbiFunction.from

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

Parses an arbitrary **JSON ABI Function** or **Human Readable ABI Function** into a typed [`AbiFunction.AbiFunction`](/docs/utilities/abifunction/types#abifunction).

## Imports

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

## Examples

### JSON ABIs

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

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

approve
//^?
```

### Human Readable ABIs

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

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

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

approve
//^?
```

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

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

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

approve
//^?
```

## Definition

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

## Parameters

### abiFunction

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

The ABI Function to parse.

### options

* **Type:** `from.Options`
* **Optional**

#### options.prepare

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

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

## Return Type

Typed ABI Function.

`from.ReturnType<abiFunction>`
