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

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

ABI-encodes a function's result (`outputs`).

## Imports

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

## Examples

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

const totalSupply = AbiFunction.from(
  'function totalSupply() returns (uint256)'
)
const output = AbiFunction.decodeResult(
  totalSupply,
  '0x000000000000000000000000000000000000000000000000000000000000002a'
)
// 42n

const data = AbiFunction.encodeResult(totalSupply, 42n) // [!code focus]
// @log: '0x000000000000000000000000000000000000000000000000000000000000002a'
```

### ABI-shorthand

You can also specify an entire ABI object and a function name as parameters to [`AbiFunction.encodeResult`](/docs/utilities/abifunction/encodeResult):

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

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

const data = AbiFunction.encodeResult(
  abi, // [!code focus]
  'totalSupply', // [!code focus]
  42n
)
// @log: '0x000000000000000000000000000000000000000000000000000000000000002a'
```

## Definition

```ts
function encodeResult<abi, name, args, as, abiFunction, allNames>(
  abi: abi | Abi.Abi | readonly unknown[],
  name: Hex.Hex | (name extends allNames ? name : never),
  output: encodeResult.Output<abiFunction, as>,
  options?: encodeResult.Options<as>,
): Hex.Hex
```

## Parameters

### abi

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

### name

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

### output

* **Type:** `encodeResult.Output<abiFunction, as>`

The function output to encode.

### options

* **Type:** `encodeResult.Options<as>`
* **Optional**

Encoding options.

#### options.as

* **Type:** `"Array" | "Object" | as`
* **Optional**

## Return Type

The encoded function output.

`Hex.Hex`
