# TxEnvelopeLegacy.from

Converts an arbitrary transaction object into a legacy Transaction Envelope.

## Imports

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

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

## Examples

```ts twoslash
import { TxEnvelopeLegacy, Value } from 'ox'

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

### Attaching Signatures

It is possible to attach a `signature` to the transaction envelope.

```ts twoslash
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 envelope_signed = TxEnvelopeLegacy.from(envelope, {
  // [!code focus]
  signature // [!code focus]
}) // [!code focus]
// @log: {
// @log:   authorizationList: [...],
// @log:   chainId: 1,
// @log:   gasPrice: 10000000000n,
// @log:   to: '0x0000000000000000000000000000000000000000',
// @log:   type: 'eip7702',
// @log:   value: 1000000000000000000n,
// @log:   r: 125...n,
// @log:   s: 642...n,
// @log:   yParity: 0,
// @log: }
```

### From Serialized

It is possible to instantiate an legacy Transaction Envelope from a [`TxEnvelopeLegacy.Serialized`](/api/TxEnvelopeLegacy/types#serialized) value.

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

const envelope = TxEnvelopeLegacy.from(
  '0xf858018203118502540be4008504a817c800809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c08477359400e1a001627c687261b0e7f8638af1112efa8a77e23656f6e7945275b19e9deed80261'
)
// @log: {
// @log:   chainId: 1,
// @log:   gasPrice: 10000000000n,
// @log:   to: '0x0000000000000000000000000000000000000000',
// @log:   type: 'legacy',
// @log:   value: 1000000000000000000n,
// @log: }
```

## Definition

```ts
function from<envelope, signature>(
  envelope: envelope | UnionPartialBy<TxEnvelopeLegacy, 'type'> | Hex.Hex,
  options?: from.Options<signature>,
): from.ReturnType<envelope, signature>
```

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

## Parameters

### envelope

* **Type:** `envelope | UnionPartialBy<TxEnvelopeLegacy, 'type'> | Hex.Hex`

The transaction object to convert.

### options

* **Type:** `from.Options<signature>`
* **Optional**

Options.

#### options.signature

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

## Return Type

A legacy Transaction Envelope.

`from.ReturnType<envelope, signature>`
