> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Transaction

> Complete Ethereum transaction encoding/decoding for all transaction types

<Card title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/transaction.ts">
  Run Transaction examples in the interactive playground
</Card>

# Transaction

<Tip>
  **New to transactions?** Start with [Transaction Fundamentals](/primitives/transaction/fundamentals) to learn about transaction types, lifecycle, signing, and gas mechanics.
</Tip>

Complete Ethereum transaction implementation supporting all transaction types from Legacy to EIP-7702.

## Overview

Transaction module provides type-safe encoding, decoding, signing, and hashing for all Ethereum transaction types. Supports Legacy (Type 0), EIP-2930 (Type 1), EIP-1559 (Type 2), EIP-4844 (Type 3), and EIP-7702 (Type 4) transactions with full RLP serialization.

## Quick Start

<Tabs>
  <Tab title="Basic Usage">
    ```typescript theme={null}
    import * as Transaction from 'tevm/Transaction'
    import * as Address from 'tevm/Address'

    // Create a transaction
    const tx: Transaction.EIP1559 = {
      type: Transaction.Type.EIP1559,
      chainId: 1n,
      nonce: 0n,
      maxPriorityFeePerGas: 1000000000n,
      maxFeePerGas: 20000000000n,
      gasLimit: 21000n,
      to: addressBytes,
      value: 1000000000000000000n,
      data: new Uint8Array(),
      accessList: [],
      yParity: 0,
      r: signatureR,
      s: signatureS,
    }

    // Serialize to bytes
    const serialized = Transaction.serialize(tx)

    // Compute transaction hash
    const hash = Transaction.hash(tx)

    // Get signing hash
    const signingHash = Transaction.getSigningHash(tx)

    // Recover sender from signature
    const sender = Transaction.getSender(tx)

    // Deserialize from bytes
    const decoded = Transaction.deserialize(serialized)

    // Detect transaction type from bytes
    const type = Transaction.detectType(serialized)
    ```
  </Tab>

  <Tab title="Type-Specific Operations">
    ```typescript theme={null}
    import * as Transaction from 'tevm/Transaction'

    // Legacy transaction
    const legacy: Transaction.Legacy = {
      type: Transaction.Type.Legacy,
      nonce: 0n,
      gasPrice: 20000000000n,
      gasLimit: 21000n,
      to: addressBytes,
      value: 1000000000000000000n,
      data: new Uint8Array(),
      v: 27n,
      r: signatureR,
      s: signatureS,
    }

    // Get chain ID from legacy v value
    const chainId = Transaction.getChainId(legacy)

    // EIP-1559 transaction
    const eip1559: Transaction.EIP1559 = { /* ... */ }
    const effectiveGasPrice = Transaction.EIP1559.getEffectiveGasPrice(
      eip1559,
      baseFee
    )

    // EIP-4844 blob transaction
    const eip4844: Transaction.EIP4844 = {
      type: Transaction.Type.EIP4844,
      chainId: 1n,
      nonce: 0n,
      maxPriorityFeePerGas: 1000000000n,
      maxFeePerGas: 20000000000n,
      gasLimit: 100000n,
      to: addressBytes,
      value: 0n,
      data: new Uint8Array(),
      accessList: [],
      maxFeePerBlobGas: 1000000000n,
      blobVersionedHashes: [hash1, hash2],
      yParity: 0,
      r: signatureR,
      s: signatureS,
    }

    const blobCost = Transaction.EIP4844.getBlobGasCost(eip4844, blobBaseFee)
    ```
  </Tab>

  <Tab title="Utilities">
    ```typescript theme={null}
    import * as Transaction from 'tevm/Transaction'

    // Format for display
    const formatted = Transaction.format(tx)
    // "EIP-1559 tx to 0x..., value: 1 ETH, nonce: 0"

    // Get gas price (handles all types)
    const gasPrice = Transaction.getGasPrice(tx, baseFee)

    // Check if transaction has access list
    if (Transaction.hasAccessList(tx)) {
      const accessList = Transaction.getAccessList(tx)
    }

    // Get chain ID
    const chainId = Transaction.getChainId(tx)

    // Check if signed
    if (Transaction.isSigned(tx)) {
      const sender = Transaction.getSender(tx)
    }

    // Assert signed (throws if not)
    Transaction.assertSigned(tx)

    // Verify signature
    const isValid = Transaction.verifySignature(tx)
    ```
  </Tab>
</Tabs>

### Effect Schema

```ts theme={null}
import { TransactionSchema } from '@tevm/voltaire/Transaction/effect'

// From RPC (legacy)
const tx = TransactionSchema.fromRpc({ type: '0x0', nonce: '0x0', gas: '0x5208', to: '0x' + '11'.repeat(20), value: '0x0', data: '0x' })
const hash = tx.hash()
const serialized = tx.serialize()
```

## Quick Reference

### Core Operations

| Method                                                       | Description                       |
| ------------------------------------------------------------ | --------------------------------- |
| [`serialize(tx)`](/primitives/transaction/serialization)     | RLP encode to bytes               |
| [`deserialize(data)`](/primitives/transaction/serialization) | RLP decode from bytes             |
| [`detectType(data)`](/primitives/transaction/detect-type)    | Detect type from serialized bytes |
| [`hash(tx)`](/primitives/transaction/hashing)                | Compute transaction hash          |
| [`getSigningHash(tx)`](/primitives/transaction/hashing)      | Get hash to sign                  |

### Signature Operations

| Method                                                   | Description            |
| -------------------------------------------------------- | ---------------------- |
| [`getSender(tx)`](/primitives/transaction/signing)       | Recover sender address |
| [`verifySignature(tx)`](/primitives/transaction/signing) | Validate signature     |
| [`isSigned(tx)`](/primitives/transaction/signing)        | Check if signed        |
| [`assertSigned(tx)`](/primitives/transaction/signing)    | Assert signed (throws) |

### RPC Conversion

| Method                                                  | Description                |
| ------------------------------------------------------- | -------------------------- |
| [`toRpc(tx)`](/primitives/transaction/serialization)    | Convert to JSON-RPC format |
| [`fromRpc(rpc)`](/primitives/transaction/serialization) | Parse from JSON-RPC format |

### Utilities

| Method                                                               | Description             |
| -------------------------------------------------------------------- | ----------------------- |
| [`getChainId(tx)`](/primitives/transaction/get-chain-id)             | Extract chain ID        |
| [`getGasPrice(tx, baseFee?)`](/primitives/transaction/get-gas-price) | Get effective gas price |
| [`hasAccessList(tx)`](/primitives/transaction/has-access-list)       | Check for access list   |
| [`getAccessList(tx)`](/primitives/transaction/get-access-list)       | Get access list         |
| [`format(tx)`](/primitives/transaction/format)                       | Format for display      |

## Transaction Types

| Type   | Name                                        | Description                                       |
| ------ | ------------------------------------------- | ------------------------------------------------- |
| `0x00` | [Legacy](/primitives/transaction/legacy)    | Original format with fixed gas price              |
| `0x01` | [EIP-2930](/primitives/transaction/eip2930) | Access list transactions for gas optimization     |
| `0x02` | [EIP-1559](/primitives/transaction/eip1559) | Dynamic fee market with base fee and priority fee |
| `0x03` | [EIP-4844](/primitives/transaction/eip4844) | Blob transactions for L2 data availability        |
| `0x04` | [EIP-7702](/primitives/transaction/eip7702) | EOA delegation to smart contracts                 |

## Type Definitions

```typescript theme={null}
// Transaction type enum
enum Type {
  Legacy = 0x00,
  EIP2930 = 0x01,
  EIP1559 = 0x02,
  EIP4844 = 0x03,
  EIP7702 = 0x04,
}

// Legacy transaction (Type 0)
type Legacy = {
  type: Type.Legacy
  nonce: bigint
  gasPrice: bigint
  gasLimit: bigint
  to: AddressType | null
  value: bigint
  data: Uint8Array
  v: bigint
  r: Uint8Array
  s: Uint8Array
}

// EIP-2930 transaction (Type 1)
type EIP2930 = {
  type: Type.EIP2930
  chainId: bigint
  nonce: bigint
  gasPrice: bigint
  gasLimit: bigint
  to: AddressType | null
  value: bigint
  data: Uint8Array
  accessList: AccessList
  yParity: number
  r: Uint8Array
  s: Uint8Array
}

// EIP-1559 transaction (Type 2)
type EIP1559 = {
  type: Type.EIP1559
  chainId: bigint
  nonce: bigint
  maxPriorityFeePerGas: bigint
  maxFeePerGas: bigint
  gasLimit: bigint
  to: AddressType | null
  value: bigint
  data: Uint8Array
  accessList: AccessList
  yParity: number
  r: Uint8Array
  s: Uint8Array
}

// EIP-4844 transaction (Type 3)
type EIP4844 = {
  type: Type.EIP4844
  chainId: bigint
  nonce: bigint
  maxPriorityFeePerGas: bigint
  maxFeePerGas: bigint
  gasLimit: bigint
  to: AddressType  // Cannot be null for blob transactions
  value: bigint
  data: Uint8Array
  accessList: AccessList
  maxFeePerBlobGas: bigint
  blobVersionedHashes: readonly VersionedHash[]
  yParity: number
  r: Uint8Array
  s: Uint8Array
}

// EIP-7702 transaction (Type 4)
type EIP7702 = {
  type: Type.EIP7702
  chainId: bigint
  nonce: bigint
  maxPriorityFeePerGas: bigint
  maxFeePerGas: bigint
  gasLimit: bigint
  to: AddressType | null
  value: bigint
  data: Uint8Array
  accessList: AccessList
  authorizationList: AuthorizationList
  yParity: number
  r: Uint8Array
  s: Uint8Array
}

// Union type for all transactions
type Any = Legacy | EIP2930 | EIP1559 | EIP4844 | EIP7702
```

Source: [types.ts](https://github.com/evmts/voltaire/blob/main/src/primitives/Transaction/types.ts)

## API Methods

### Serialization

* [serialize](serialize) - RLP encode transaction to bytes
* [deserialize](deserialize) - RLP decode transaction from bytes
* [detectType](detectType) - Detect transaction type from serialized bytes
* [toRpc](toRpc) - Convert transaction to JSON-RPC format
* [fromRpc](fromRpc) - Parse transaction from JSON-RPC format

### Hashing

* [hash](hash) - Compute transaction hash
* [getSigningHash](getSigningHash) - Get hash to sign

### Signatures

* [getSender](getSender) - Recover sender address from signature
* [verifySignature](verifySignature) - Validate transaction signature
* [isSigned](isSigned) - Check if transaction is signed
* [assertSigned](assertSigned) - Assert transaction is signed (throws if not)

### Gas Pricing

* [getGasPrice](getGasPrice) - Calculate effective gas price
* [getEffectiveGasPrice](getEffectiveGasPrice) - Get effective gas price for EIP-1559
* [getBlobGasCost](getBlobGasCost) - Calculate blob gas cost for EIP-4844

### Access Lists

* [hasAccessList](hasAccessList) - Check if transaction has access list
* [getAccessList](getAccessList) - Retrieve access list data

### Utilities

* [getChainId](getChainId) - Extract chain ID from transaction
* [format](format) - Format transaction for display

## Usage Patterns

Common patterns for working with transactions:

[View usage patterns →](/primitives/transaction/usage-patterns)

## Tree-Shaking

Import only what you need:

```typescript theme={null}
// Namespace import (all methods)
import * as Transaction from 'tevm/Transaction';

// Granular imports (tree-shakeable)
import { serialize } from 'tevm/Transaction/serialize';
import { hash } from 'tevm/Transaction/hash';
import { getSender } from 'tevm/Transaction/getSender';
```

## Related

* [Transaction (Effect)](https://voltaire-effect.tevm.sh/primitives/transaction) - Effect.ts integration with Schema validation
* [Address](/primitives/address) - 20-byte Ethereum addresses
* [Keccak256](/crypto/keccak256) - 32-byte hash values
* [Hex](/primitives/hex) - Hex string utilities
* [RLP](/primitives/rlp) - Recursive Length Prefix encoding
* [AccessList](/primitives/access-list) - Pre-declared account/storage access
* [Blob](/primitives/blob) - Blob data for EIP-4844
* [Authorization](/primitives/authorization) - EOA delegation for EIP-7702
* [FeeMarket](/primitives/fee-market) - Base fee and priority fee calculations
* [GasConstants](/primitives/gas-constants) - Gas intrinsic costs
* [Secp256k1](/crypto/secp256k1) - ECDSA signature utilities

## Specification

* [EIP-155](https://eips.ethereum.org/EIPS/eip-155) - Replay protection
* [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718) - Typed transaction envelope
* [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930) - Access lists
* [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) - Fee market
* [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844) - Blob transactions
* [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) - EOA delegation
* [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf) - Transaction spec (Section 4.2)
