# TxEnvelopeLegacy.serialize

Serializes a [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/api/TxEnvelopeLegacy/types#txenvelopelegacy).

## Imports

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

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

## Examples

```ts twoslash
// @noErrors
import { TxEnvelopeLegacy } from 'ox'

const envelope = TxEnvelopeLegacy.from({
  chainId: 1,
  gasPrice: Value.fromGwei('10'),
  to: '0x0000000000000000000000000000000000000000',
  value: Value.fromEther('1')
})

const serialized = TxEnvelopeLegacy.serialize(envelope) // [!code focus]
```

### Attaching Signatures

It is possible to attach a `signature` to the serialized Transaction Envelope.

```ts twoslash
// @noErrors
import { Secp256k1, TxEnvelopeLegacy, Value } from 'ox'

const envelope = TxEnvelopeLegacy.from({
  chainId: 1,
  gasPrice: Value.fromGwei('10'),
  to: '0x0000000000000000000000000000000000000000',
  value: Value.fromEther('1')
})

const signature = Secp256k1.sign({
  payload: TxEnvelopeLegacy.getSignPayload(envelope),
  privateKey: '0x...'
})

const serialized = TxEnvelopeLegacy.serialize(envelope, {
  // [!code focus]
  signature // [!code focus]
}) // [!code focus]

// ... send `serialized` transaction to JSON-RPC `eth_sendRawTransaction`
```

## Definition

```ts
function serialize(
  envelope: PartialBy<TxEnvelopeLegacy, 'type'>,
  options?: serialize.Options,
): Serialized
```

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

## Parameters

### envelope

* **Type:** `PartialBy<TxEnvelopeLegacy, 'type'>`

The Transaction Envelope to serialize.

### options

* **Type:** `serialize.Options`
* **Optional**

Options.

#### options.signature

* **Type:** `{ r: 0x${string}; s: 0x${string}; yParity: number; }`
* **Optional**

Signature to append to the serialized Transaction Envelope.

## Return Type

The serialized Transaction Envelope.

[`Serialized`](/api/TxEnvelopeLegacy/types#txenvelopelegacyserialized)
