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

# TxEnvelopeLegacy

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

Utility functions for working
with **Legacy Transaction Envelopes**.

## Examples

Below are some examples demonstrating common usages of the `TxEnvelopeLegacy` module:

* [Instantiating](#instantiating)

* [Signing](#signing)

* [Serializing](#serializing)

* [Sending](#sending)

* [Computing Hashes](#computing-hashes)

### Instantiating

Transaction Envelopes can be instantiated using [`TxEnvelopeLegacy.from`](/docs/utilities/txenvelopelegacy/from):

```ts twoslash
// @noErrors
import { TxEnvelopeLegacy, Value } from 'viem/utils'

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

*

### Signing

Transaction Envelopes can be signed using [`TxEnvelopeLegacy.getSignPayload`](/docs/utilities/txenvelopelegacy/getSignPayload) and a signing function such as [`Secp256k1.sign`](/docs/utilities/secp256k1/sign) or [`P256.sign`](/docs/utilities/p256/sign):

```ts twoslash
// @noErrors
import { Secp256k1, TxEnvelopeLegacy } from 'viem/utils'

const envelope = TxEnvelopeLegacy.from({
  nonce: 0n,
  gasPrice: 1000000000n,
  gas: 21000n,
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1000000000000000000n
})

const signature = Secp256k1.sign({
  // [!code focus]
  payload: TxEnvelopeLegacy.getSignPayload(envelope), // [!code focus]
  privateKey: '0x...' // [!code focus]
}) // [!code focus]

const envelope_signed = TxEnvelopeLegacy.from(envelope, {
  signature
})
```

### Serializing

Transaction Envelopes can be serialized using [`TxEnvelopeLegacy.serialize`](/docs/utilities/txenvelopelegacy/serialize):

```ts twoslash
// @noErrors
import { TxEnvelopeLegacy, Value } from 'viem/utils'

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

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

### Sending

We can send a Transaction Envelope to the network by serializing the signed envelope with `.serialize`, and then broadcasting it over JSON-RPC with `eth_sendRawTransaction`.

In this example, we will use [`RpcTransport.fromHttp`](https://oxlib.sh/api/RpcTransport/fromHttp) to broadcast a `eth_sendRawTransaction` request over HTTP JSON-RPC.

```ts twoslash
// @noErrors
import {
  RpcTransport,
  TxEnvelopeLegacy,
  Secp256k1,
  Value
} from 'viem/utils'

// Construct the Envelope.
const envelope = TxEnvelopeLegacy.from({
  chainId: 1,
  gasPrice: Value.fromGwei('10'),
  nonce: 69n,
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: Value.fromEther('1.5')
})

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

// Serialize the Envelope with the Signature. // [!code focus]
const serialized = TxEnvelopeLegacy.serialize(envelope, {
  // [!code focus]
  signature // [!code focus]
}) // [!code focus]

// Broadcast the Envelope with `eth_sendRawTransaction`. // [!code focus]
const transport = RpcTransport.fromHttp(
  'https://1.rpc.thirdweb.com'
) // [!code focus]
const hash = await transport.request({
  // [!code focus]
  method: 'eth_sendRawTransaction', // [!code focus]
  params: [serialized] // [!code focus]
}) // [!code focus]
```

If you are interfacing with an RPC that supports `eth_sendTransaction`, you can also use
[`TxEnvelopeLegacy.toRpc`](/docs/utilities/txenvelopelegacy/toRpc) to convert an Envelope to an RPC-compatible format.
This means you can skip the ceremony of manually filling & signing the Transaction.

```ts twoslash
// @noErrors
import 'ox/window'
import { Provider, TxEnvelopeLegacy, Value } from 'viem/utils'

const envelope = TxEnvelopeLegacy.from({
  chainId: 1,
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: Value.fromEther('1.5')
})

const envelope_rpc = TxEnvelopeLegacy.toRpc(envelope)

const provider = Provider.from(window.ethereum)
const hash = await provider.request({
  method: 'eth_sendTransaction',
  params: [envelope_rpc]
})
```

### Computing Hashes

Transaction Hashes can be computed using [`TxEnvelopeLegacy.hash`](/docs/utilities/txenvelopelegacy/hash):

```ts twoslash
// @noErrors
import { Secp256k1, TxEnvelopeLegacy } from 'viem/utils'

const envelope = TxEnvelopeLegacy.from({
  chainId: 1,
  nonce: 0n,
  gasPrice: 1000000000n,
  gas: 21000n,
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: 1000000000000000000n,
  data: '0x'
})

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

const envelope_signed = TxEnvelopeLegacy.from(envelope, {
  signature
})

const hash = TxEnvelopeLegacy.hash(envelope_signed) // [!code focus]
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`TxEnvelopeLegacy.assert`](/docs/utilities/txenvelopelegacy/assert) | Asserts a [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacy) is valid. |
| [`TxEnvelopeLegacy.deserialize`](/docs/utilities/txenvelopelegacy/deserialize) | Deserializes a [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacy) from its serialized form. |
| [`TxEnvelopeLegacy.from`](/docs/utilities/txenvelopelegacy/from) | Converts an arbitrary transaction object into a legacy Transaction Envelope. |
| [`TxEnvelopeLegacy.getSignPayload`](/docs/utilities/txenvelopelegacy/getSignPayload) | Returns the payload to sign for a [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacy). |
| [`TxEnvelopeLegacy.hash`](/docs/utilities/txenvelopelegacy/hash) | Hashes a [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacy). This is the "transaction hash". |
| [`TxEnvelopeLegacy.serialize`](/docs/utilities/txenvelopelegacy/serialize) | Serializes a [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacy). |
| [`TxEnvelopeLegacy.toRpc`](/docs/utilities/txenvelopelegacy/toRpc) | Converts an [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacy) to an [`TxEnvelopeLegacy.Rpc`](/docs/utilities/txenvelopelegacy/types#rpc). |
| [`TxEnvelopeLegacy.validate`](/docs/utilities/txenvelopelegacy/validate) | Validates a [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacy). Returns `true` if the envelope is valid, `false` otherwise. |

## Types

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`TxEnvelopeLegacy.Rpc`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacyrpc) |  |
| [`TxEnvelopeLegacy.Serialized`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacyserialized) |  |
| [`TxEnvelopeLegacy.Signed`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacysigned) |  |
| [`TxEnvelopeLegacy.TxEnvelopeLegacy`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacytxenvelopelegacy) |  |
| [`TxEnvelopeLegacy.Type`](/docs/utilities/txenvelopelegacy/types#txenvelopelegacytype) |  |
