Skip to main content

Try it Live

Run Transaction examples in the interactive playground

Transaction

New to transactions? Start with Transaction Fundamentals to learn about transaction types, lifecycle, signing, and gas mechanics.
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

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)

Effect Schema

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

MethodDescription
serialize(tx)RLP encode to bytes
deserialize(data)RLP decode from bytes
detectType(data)Detect type from serialized bytes
hash(tx)Compute transaction hash
getSigningHash(tx)Get hash to sign

Signature Operations

MethodDescription
getSender(tx)Recover sender address
verifySignature(tx)Validate signature
isSigned(tx)Check if signed
assertSigned(tx)Assert signed (throws)

RPC Conversion

MethodDescription
toRpc(tx)Convert to JSON-RPC format
fromRpc(rpc)Parse from JSON-RPC format

Utilities

MethodDescription
getChainId(tx)Extract chain ID
getGasPrice(tx, baseFee?)Get effective gas price
hasAccessList(tx)Check for access list
getAccessList(tx)Get access list
format(tx)Format for display

Transaction Types

TypeNameDescription
0x00LegacyOriginal format with fixed gas price
0x01EIP-2930Access list transactions for gas optimization
0x02EIP-1559Dynamic fee market with base fee and priority fee
0x03EIP-4844Blob transactions for L2 data availability
0x04EIP-7702EOA delegation to smart contracts

Type Definitions

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

API Methods

Serialization

  • serialize - RLP encode transaction to bytes
  • deserialize - RLP decode transaction from bytes
  • detectType - Detect transaction type from serialized bytes
  • toRpc - Convert transaction to JSON-RPC format
  • fromRpc - Parse transaction from JSON-RPC format

Hashing

Signatures

Gas Pricing

Access Lists

Utilities

  • getChainId - Extract chain ID from transaction
  • format - Format transaction for display

Usage Patterns

Common patterns for working with transactions: View usage patterns →

Tree-Shaking

Import only what you need:
// 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';

Specification