ethereumjs-monorepo

@ethereumjs/block / Block

Class: Block

An object that represents the block.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Block(header?, transactions?, uncleHeaders?, withdrawals?, opts?, executionWitness?)

This constructor takes the values, validates them, assigns them and freezes the object. Use the static factory methods to assist in creating a Block object from varying data types and options.

Parameters

Name Type Default value
header? BlockHeader undefined
transactions TypedTransaction[] []
uncleHeaders BlockHeader[] []
withdrawals? Withdrawal[] undefined
opts BlockOptions {}
executionWitness? null | VerkleExecutionWitness undefined

Defined in

block.ts:405

Properties

common

Readonly common: Common

Defined in

block.ts:53


executionWitness

Optional Readonly executionWitness: null | VerkleExecutionWitness

EIP-6800: Verkle Proof Data (experimental) null implies that the non default executionWitness might exist but not available and will not lead to execution of the block via vm with verkle stateless manager

Defined in

block.ts:61


Readonly header: BlockHeader

Defined in

block.ts:49


transactions

Readonly transactions: TypedTransaction[] = []

Defined in

block.ts:50


uncleHeaders

Readonly uncleHeaders: BlockHeader[] = []

Defined in

block.ts:51


withdrawals

Optional Readonly withdrawals: Withdrawal[]

Defined in

block.ts:52

Methods

errorStr

errorStr(): string

Return a compact error string representation of the object

Returns

string

Defined in

block.ts:806


ethashCanonicalDifficulty

ethashCanonicalDifficulty(parentBlock): bigint

Returns the canonical difficulty for this block.

Parameters

Name Type Description
parentBlock Block the parent of this Block

Returns

bigint

Defined in

block.ts:772


genTxTrie

genTxTrie(): Promise<Uint8Array>

Generates transaction trie for validation.

Returns

Promise<Uint8Array>

Defined in

block.ts:520


getTransactionsValidationErrors

getTransactionsValidationErrors(): string[]

Validates transaction signatures and minimum gas requirements.

Returns

string[]

an array of error strings

Defined in

block.ts:547


hash

hash(): Uint8Array

Returns the hash of the block.

Returns

Uint8Array

Defined in

block.ts:499


isGenesis

isGenesis(): boolean

Determines if this block is the genesis block.

Returns

boolean

Defined in

block.ts:506


raw

raw(): BlockBytes

Returns a Array of the raw Bytes Arrays of this block, in order.

Returns

BlockBytes

Defined in

block.ts:477


serialize

serialize(): Uint8Array

Returns the rlp encoding of the block.

Returns

Uint8Array

Defined in

block.ts:513


toJSON

toJSON(): JsonBlock

Returns the block in JSON format.

Returns

JsonBlock

Defined in

block.ts:789


transactionsAreValid

transactionsAreValid(): boolean

Validates transaction signatures and minimum gas requirements.

Returns

boolean

True if all transactions are valid, false otherwise

Defined in

block.ts:597


transactionsTrieIsValid

transactionsTrieIsValid(): Promise<boolean>

Validates the transaction trie by generating a trie and do a check on the root hash.

Returns

Promise<boolean>

True if the transaction trie is valid, false otherwise

Defined in

block.ts:529


uncleHashIsValid

uncleHashIsValid(): boolean

Validates the uncle’s hash.

Returns

boolean

true if the uncle’s hash is valid, false otherwise.

Defined in

block.ts:718


validateBlobTransactions

validateBlobTransactions(parentHeader): void

Validates that blob gas fee for each transaction is greater than or equal to the blobGasPrice for the block and that total blob gas in block is less than maximum blob gas per block

Parameters

Name Type Description
parentHeader BlockHeader header of parent block

Returns

void

Defined in

block.ts:670


validateData

validateData(onlyHeader?, verifyTxs?): Promise<void>

Validates the block data, throwing if invalid. This can be checked on the Block itself without needing access to any parent block It checks:

Parameters

Name Type Default value Description
onlyHeader boolean false if only passed the header, skip validating txTrie and unclesHash (default: false)
verifyTxs boolean true if set to false, will not check for transaction validation errors (default: true)

Returns

Promise<void>

Defined in

block.ts:613


validateGasLimit

validateGasLimit(parentBlock): void

Validates if the block gasLimit remains in the boundaries set by the protocol. Throws if invalid

Parameters

Name Type Description
parentBlock Block the parent of this Block

Returns

void

Defined in

block.ts:782


validateUncles

validateUncles(): void

Consistency checks for uncles included in the block, if any.

Throws if invalid.

The rules for uncles checked are the following: Header has at most 2 uncles. Header does not count an uncle twice.

Returns

void

Defined in

block.ts:748


withdrawalsTrieIsValid

withdrawalsTrieIsValid(): Promise<boolean>

Validates the withdrawal root

Returns

Promise<boolean>

true if the withdrawals trie root is valid, false otherwise

Defined in

block.ts:728


fromBeaconPayloadJson

Static fromBeaconPayloadJson(payload, opts?): Promise<Block>

Method to retrieve a block from a beacon payload json

Parameters

Name Type Description
payload BeaconPayloadJson json of a beacon beacon fetched from beacon apis
opts? BlockOptions BlockOptions

Returns

Promise<Block>

the block constructed block

Defined in

block.ts:393


fromBlockData

Static fromBlockData(blockData?, opts?): Block

Static constructor to create a block from a block data dictionary

Parameters

Name Type
blockData BlockData
opts? BlockOptions

Returns

Block

Defined in

block.ts:99


fromExecutionPayload

Static fromExecutionPayload(payload, opts?): Promise<Block>

Method to retrieve a block from an execution payload

Parameters

Name Type Description
payload ExecutionPayload -
opts? BlockOptions BlockOptions

Returns

Promise<Block>

the block constructed block

Defined in

block.ts:320


fromJsonRpcProvider

Static fromJsonRpcProvider(provider, blockTag, opts): Promise<Block>

Method to retrieve a block from a JSON-RPC provider and format as a Block

Parameters

Name Type Description
provider string | EthersProvider either a url for a remote provider or an Ethers JsonRpcProvider object
blockTag string | bigint block hash or block number to be run
opts BlockOptions BlockOptions

Returns

Promise<Block>

the block specified by blockTag

Defined in

block.ts:260


fromRLPSerializedBlock

Static fromRLPSerializedBlock(serialized, opts?): Block

Static constructor to create a block from a RLP-serialized block

Parameters

Name Type
serialized Uint8Array
opts? BlockOptions

Returns

Block

Defined in

block.ts:153


fromRPC

Static fromRPC(blockData, uncles?, opts?): Block

Creates a new block object from Ethereum JSON RPC.

Parameters

Name Type Description
blockData JsonRpcBlock -
uncles? any[] Optional list of Ethereum JSON RPC of uncles (eth_getUncleByBlockHashAndIndex)
opts? BlockOptions An object describing the blockchain

Returns

Block

Defined in

block.ts:249


fromValuesArray

Static fromValuesArray(values, opts?): Block

Static constructor to create a block from an array of Bytes values

Parameters

Name Type
values BlockBytes
opts? BlockOptions

Returns

Block

Defined in

block.ts:169


genTransactionsTrieRoot

Static genTransactionsTrieRoot(txs, emptyTrie?): Promise<Uint8Array>

Returns the txs trie root for array of TypedTransaction

Parameters

Name Type Description
txs TypedTransaction[] array of TypedTransaction to compute the root of
emptyTrie? Trie -

Returns

Promise<Uint8Array>

Defined in

block.ts:85


genWithdrawalsTrieRoot

Static genWithdrawalsTrieRoot(wts, emptyTrie?): Promise<Uint8Array>

Returns the withdrawals trie root for array of Withdrawal.

Parameters

Name Type Description
wts Withdrawal[] array of Withdrawal to compute the root of
emptyTrie? Trie -

Returns

Promise<Uint8Array>

Defined in

block.ts:72