Skip to main content

Try it Live

Run Transaction examples in the interactive playground

Transaction Utilities

Utility methods for working with transactions across all types.

format

Format transaction to human-readable string.

Usage

Source: format.ts:6-20

getGasPrice

Get transaction gas price (handles all types).

Parameters

  • tx: Any - Any transaction type
  • baseFee?: bigint - Required for EIP-1559+ transactions

Returns

bigint - Gas price in wei

Throws

  • Error("baseFee required for EIP-1559+ transactions") - If baseFee missing for dynamic fee transactions

Usage

Source: getGasPrice.ts:16-38

hasAccessList

Check if transaction supports access lists.

Returns

  • true - For EIP-2930, EIP-1559, EIP-4844, EIP-7702
  • false - For Legacy

Usage

Source: hasAccessList.ts:7-9

getAccessList

Get transaction access list.

Returns

  • AccessList - Transaction access list
  • [] - Empty array for Legacy transactions

Usage

Source: getAccessList.ts:7-12

getChainId

Get transaction chain ID.

Returns

  • bigint - Chain ID
  • null - For pre-EIP-155 Legacy transactions

Usage

Source: getChainId.ts:8-13

isSigned

Check if transaction has a signature.

Returns

  • true - If transaction has non-zero r and s
  • false - If r or s is all zeros

Usage

Source: isSigned.ts:7-14

assertSigned

Assert transaction is signed (throws if not).

Throws

  • Error("Transaction is not signed") - If r or s is all zeros

Usage

Source: assertSigned.ts:6-13

Usage Patterns

Transaction Cost Calculation

Replay Protection Check

Access List Extraction

Transaction Display

Signature Validation

Transaction Pool Entry

Performance Tips

  1. Cache getSender results - ECDSA recovery is expensive
  2. Batch getGasPrice calls - Reuse baseFee for multiple transactions
  3. Check isSigned before getSender - Avoid unnecessary recovery attempts
  4. Use hasAccessList before getAccessList - Skip unnecessary checks