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

# AbiConstructor.encode

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

ABI-encodes the provided constructor input (`inputs`).

## Imports

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

## Examples

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

const constructor = AbiConstructor.from(
  'constructor(address, uint256)'
)

const data = AbiConstructor.encode(constructor, {
  bytecode: '0x...',
  args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 123n]
})
```

### ABI-shorthand

You can also specify an entire ABI object as a parameter to `AbiConstructor.encode`.

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

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

const data = AbiConstructor.encode(abi, { // [!code focus]
  bytecode: '0x...', // [!code focus]
  args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 123n], // [!code focus]
}) // [!code focus]
```

### End-to-end

Below is an end-to-end example of using `AbiConstructor.encode` to encode the constructor of a contract and deploy it.

```ts twoslash
// @noErrors
import 'ox/window'
import { AbiConstructor, Hex } from 'viem/utils'

// 1. Instantiate the ABI Constructor.
const constructor = AbiConstructor.from(
  'constructor(address owner, uint256 amount)'
)

// 2. Encode the ABI Constructor.
const data = AbiConstructor.encode(constructor, {
  bytecode: '0x...',
  args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 123n]
})

// 3. Deploy the contract.
const hash = await window.ethereum!.request({
  method: 'eth_sendTransaction',
  params: [{ data }]
})
```

:::note
For simplicity, the above example uses `window.ethereum.request`, but you can use any type of JSON-RPC interface.
:::

## Definition

```ts
function encode<abi, abiConstructor>(
  abi: abi | Abi.Abi | readonly unknown[],
  options: encode.Options<abiConstructor>,
): encode.ReturnType
```

## Parameters

### abi

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

### options

* **Type:** `encode.Options<abiConstructor>`

Encoding options.

#### options.args

* **Type:** `args`

The constructor arguments to encode.

#### options.bytecode

* **Type:** `0x${string}`

The bytecode of the contract.

## Return Type

The encoded constructor.

`encode.ReturnType`
