# AbiFunction.from

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

## Imports

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

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

## Examples

### JSON ABIs

```ts twoslash
import { AbiFunction } from 'ox'

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
import { AbiFunction } from 'ox'

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
import { AbiFunction } from 'ox'

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

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

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