# TransactionRequest.toEnvelope

Converts a [`TransactionRequest.TransactionRequest`](/api/TransactionRequest/types#transactionrequest) to a [`TransactionEnvelope.TxEnvelope`](/api/TransactionEnvelope/types#txenvelope).

Dispatches to the correct concrete envelope type via [`TransactionEnvelope.getType`](/api/TransactionEnvelope/getType) (using `request.type` when present, otherwise inferring from fee/blob/authorization fields), and drops fields that do not belong to the chosen type.

For EIP-4844, if `blobs` is provided without `sidecars`, sidecars and `blobVersionedHashes` are derived via the `kzg` option. If `sidecars` is already provided, it is passed through unchanged.

Inputs are expected to be in canonical form (`bigint` numerics and `'eip1559'`-style `type` strings). Pass RPC-shaped payloads through [`TransactionRequest.fromRpc`](/api/TransactionRequest/fromRpc) first.

## Imports

:::code-group

```ts [Named]
import { TransactionRequest } from 'ox'
```

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

:::

## Examples

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

const envelope = TransactionRequest.toEnvelope({
  chainId: 1,
  maxFeePerGas: 1n,
  to: '0x0000000000000000000000000000000000000000',
  value: 1n
})
// @log: {
// @log:   chainId: 1,
// @log:   maxFeePerGas: 1n,
// @log:   to: '0x0000000000000000000000000000000000000000',
// @log:   type: 'eip1559',
// @log:   value: 1n,
// @log: }
```

## Definition

```ts
function toEnvelope(
  request: TransactionRequest,
  options?: toEnvelope.Options,
): TxEnvelope.TxEnvelope
```

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

## Parameters

### request

* **Type:** `TransactionRequest`

The transaction request to convert.

#### request.accessList

* **Type:** `readonly { address: abitype_Address; storageKeys: readonly 0x${string}[]; }[]`
* **Optional**

EIP-2930 Access List.

#### request.authorizationList

* **Type:** `readonly { address: abitype_Address; chainId: numberType; nonce: bigintType; r: 0x${string}; s: 0x${string}; yParity: numberType; }[]`
* **Optional**

EIP-7702 Authorization List.

#### request.blobVersionedHashes

* **Type:** `readonly 0x${string}[]`
* **Optional**

Versioned hashes of blobs to be included in the transaction.

#### request.blobs

* **Type:** `readonly 0x${string}[]`
* **Optional**

Raw blob data.

#### request.chainId

* **Type:** `numberType`
* **Optional**

EIP-155 Chain ID.

#### request.data

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

Contract code or a hashed method call with encoded args

#### request.from

* **Type:** `Address.Address | undefined`
* **Optional**

Sender of the transaction.

#### request.gas

* **Type:** `bigintType`
* **Optional**

Gas provided for transaction execution

#### request.gasPrice

* **Type:** `bigintType`
* **Optional**

Base fee per gas.

#### request.input

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

#### request.maxFeePerBlobGas

* **Type:** `bigintType`
* **Optional**

Maximum total fee per gas sender is willing to pay for blob gas (in wei).

#### request.maxFeePerGas

* **Type:** `bigintType`
* **Optional**

Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas).

#### request.maxPriorityFeePerGas

* **Type:** `bigintType`
* **Optional**

Max priority fee per gas (in wei).

#### request.nonce

* **Type:** `bigintType`
* **Optional**

Unique number identifying this transaction

#### request.r

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

ECDSA signature r.

#### request.s

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

ECDSA signature s.

#### request.to

* **Type:** `Address.Address | null | undefined`
* **Optional**

Transaction recipient

#### request.type

* **Type:** `type`
* **Optional**

Transaction type

#### request.v

* **Type:** `numberType`
* **Optional**

#### request.value

* **Type:** `bigintType`
* **Optional**

Value in wei sent with this transaction

#### request.yParity

* **Type:** `numberType`
* **Optional**

ECDSA signature yParity.

### options

* **Type:** `toEnvelope.Options`
* **Optional**

Options.

#### options.kzg

* **Type:** `Kzg`
* **Optional**

KZG context used to derive EIP-4844 `sidecars` and `blobVersionedHashes`
from raw `blobs`. Required when `blobs` is provided without `sidecars`
or `blobVersionedHashes`.

## Return Type

A transaction envelope.

`TxEnvelope.TxEnvelope`
