Skip to main content

Overview

BlockBody contains the executable content of a block: transactions, uncle/ommer blocks, and (post-Shanghai) withdrawals.
import * as BlockBody from '@voltaire/primitives/BlockBody'

const body = BlockBody.from({
  transactions: [tx1, tx2, tx3],
  ommers: [],
  withdrawals: [w1, w2],
})

Type Definition

type BlockBodyType = {
  readonly transactions: readonly Transaction[]
  readonly ommers: readonly UncleType[]
  readonly withdrawals?: readonly WithdrawalType[]
}
Fields:
  • transactions - Ordered list of transactions in the block
  • ommers - Uncle/ommer block headers (deprecated post-merge)
  • withdrawals - Beacon chain withdrawals (post-Shanghai)

Creating BlockBody

from

Universal constructor from components.
import * as BlockBody from '@voltaire/primitives/BlockBody'

// Basic block with just transactions
const body = BlockBody.from({
  transactions: [legacyTx, eip1559Tx, eip4844Tx],
  ommers: [],
})

// Post-Shanghai block with withdrawals
const shanghaiBody = BlockBody.from({
  transactions: [tx1, tx2],
  ommers: [],
  withdrawals: [
    { index: 0n, validatorIndex: 123n, address: "0x...", amount: 1000000000n },
    { index: 1n, validatorIndex: 456n, address: "0x...", amount: 2000000000n },
  ],
})

Transaction Types

BlockBody supports all transaction types:
TypeDescriptionIntroduced
LegacyOriginal transaction formatGenesis
EIP-2930Access list transactionsBerlin
EIP-1559Fee market transactionsLondon
EIP-4844Blob transactionsCancun
EIP-7702Account abstractionPrague
const body = BlockBody.from({
  transactions: [
    legacyTx,      // Type 0
    eip2930Tx,     // Type 1
    eip1559Tx,     // Type 2
    eip4844Tx,     // Type 3
  ],
  ommers: [],
})

Ommers (Uncle Blocks)

Ommers are deprecated post-merge. Always use empty array for new blocks.
// Pre-merge block with ommers
const premergebody = BlockBody.from({
  transactions: [],
  ommers: [uncleHeader1, uncleHeader2],
})

// Post-merge block (no ommers)
const postmergeBody = BlockBody.from({
  transactions: [],
  ommers: [],
})

Withdrawals (Post-Shanghai)

Withdrawals represent ETH being withdrawn from the beacon chain to execution layer.
const withdrawal = {
  index: 12345n,           // Global withdrawal index
  validatorIndex: 100n,    // Validator being withdrawn from
  address: "0xabc...",     // Recipient address
  amount: 32000000000n,    // Amount in Gwei (not Wei!)
}

const body = BlockBody.from({
  transactions: [],
  ommers: [],
  withdrawals: [withdrawal],
})
Withdrawal amounts are in Gwei (10^9 Wei), not Wei!

See Also