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

# AbiError.encode

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

ABI-encodes the provided error input (`inputs`), prefixed with the 4 byte error selector.

## Imports

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

## Examples

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

const error = AbiError.from(
  'error InvalidSignature(uint r, uint s, uint8 yParity)'
)

const data = AbiError.encode(
  // [!code focus]
  error, // [!code focus]
  [1n, 2n, 0] // [!code focus]
) // [!code focus]
// @log: '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
```

### ABI-shorthand

You can also specify an entire ABI object and an error name as parameters to `AbiError.encode`.

```ts twoslash
// @noErrors
import { Abi, AbiError } from 'viem/utils'

const abi = Abi.from([...])

const data = AbiError.encode(
  abi, // [!code hl]
  'InvalidSignature', // [!code hl]
  [1n, 2n, 0]
)
```

## Definition

```ts
function encode<abi, name, args, abiError, allNames>(
  abi: abi | Abi.Abi | readonly unknown[],
  name: Hex.Hex | (name extends allNames ? name : never),
  args: encode.Args<abiError>,
): encode.ReturnType
```

## Parameters

### abi

* **Type:** `abi | Abi.Abi | readonly unknown[]`

### name

* **Type:** `Hex.Hex | (name extends allNames ? name : never)`

### args

* **Type:** `encode.Args<abiError>`

Error arguments

## Return Type

ABI-encoded error name and arguments

`encode.ReturnType`
