> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Abi.encode

> Encode function calldata using a full ABI

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/abi.ts">
  Run ABI examples in the interactive playground
</Card>

## Overview

`Abi.encode` encodes function calldata (selector + parameters) using a full ABI. It looks up the function by name, then encodes the arguments according to the function inputs.

## Quick Start

<Tabs>
  <Tab title="Abi Instance">
    ```typescript theme={null}
    import { Abi } from '@tevm/voltaire/Abi';
    import { Hex } from '@tevm/voltaire/Hex';

    const abi = Abi([
      {
        type: 'function',
        name: 'transfer',
        stateMutability: 'nonpayable',
        inputs: [
          { type: 'address', name: 'to' },
          { type: 'uint256', name: 'amount' }
        ],
        outputs: [{ type: 'bool' }]
      }
    ] as const);

    const calldata = abi.encode('transfer', [
      '0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e',
      1000n
    ]);

    const hex = Hex.fromBytes(calldata);
    ```
  </Tab>

  <Tab title="Explicit Function Item">
    ```typescript theme={null}
    import { Abi } from '@tevm/voltaire/Abi';

    const transfer = {
      type: 'function',
      name: 'transfer',
      inputs: [
        { type: 'address', name: 'to' },
        { type: 'uint256', name: 'amount' }
      ],
      outputs: [{ type: 'bool' }]
    } as const;

    const calldata = Abi.Function.encodeParams(transfer, [
      '0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e',
      1000n
    ]);
    ```
  </Tab>
</Tabs>

## Parameters Only

If you need only the parameters (no selector), use `Abi.encodeParameters`:

```typescript theme={null}
import { Abi } from '@tevm/voltaire/Abi';

const params = [
  { type: 'address' },
  { type: 'uint256' }
] as const;

const encoded = Abi.encodeParameters(params, [
  '0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e',
  1000n
]);
```

## Overloads and Ambiguity

`Abi.encode` matches by function **name**. If your ABI contains overloads, select the exact function item:

```typescript theme={null}
const signature = 'foo(address,uint256)';
const fn = abi.find(
  (item) =>
    item.type === 'function' &&
    Abi.Function.getSignature(item) === signature
);

const data = Abi.Function.encodeParams(fn, [
  '0x742d35Cc6634C0532925a3b844Bc9e7595f51e3e',
  1n
]);
```

## Error Handling

```typescript theme={null}
import { Abi, AbiItemNotFoundError, AbiEncodingError } from '@tevm/voltaire/Abi';

try {
  abi.encode('missingFunction', []);
} catch (error) {
  if (error instanceof AbiItemNotFoundError) {
    console.error('Function not found in ABI');
  }
  if (error instanceof AbiEncodingError) {
    console.error('Invalid parameter value');
  }
}
```

## See Also

* [decode](/primitives/abi/decode) - Decode function return values
* [decodeData](/primitives/abi/decode-data) - Decode calldata by selector
* [Function.encodeParams](/primitives/abi/function-encode-params) - Function-specific encoding
* [Encoding](/primitives/abi/encoding) - ABI encoding rules
