# AbiFunction.encodeResult

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

## Imports

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

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

## Examples

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

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`](/api/AbiFunction/encodeResult):

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

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

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

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