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

# TransactionRequest.toEnvelope

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

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

Dispatches to the correct concrete envelope type via [`TransactionEnvelope.getType`](/docs/utilities/txenvelope/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`](/docs/utilities/transactionrequest/fromRpc) first.

## Imports

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

## Examples

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

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
```

## 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`
