Skip to content

Latest commit

 

History

History
668 lines (377 loc) · 14.8 KB

File metadata and controls

668 lines (377 loc) · 14.8 KB

@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?)

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 {}

Defined in

block.ts:361

Properties

common

Readonly common: Common

Defined in

block.ts:52


header

Readonly header: BlockHeader

Defined in

block.ts:47


transactions

Readonly transactions: TypedTransaction[] = []

Defined in

block.ts:48


txTrie

Readonly txTrie: Trie

Defined in

block.ts:51


uncleHeaders

Readonly uncleHeaders: BlockHeader[] = []

Defined in

block.ts:49


withdrawals

Optional Readonly withdrawals: Withdrawal[]

Defined in

block.ts:50

Methods

errorStr

errorStr(): string

Return a compact error string representation of the object

Returns

string

Defined in

block.ts:701


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:667


genTxTrie

genTxTrie(): Promise<void>

Generates transaction trie for validation.

Returns

Promise<void>

Defined in

block.ts:442


getTransactionsValidationErrors

getTransactionsValidationErrors(): string[]

Validates transaction signatures and minimum gas requirements.

Returns

string[]

an array of error strings

Defined in

block.ts:470


hash

hash(): Uint8Array

Returns the hash of the block.

Returns

Uint8Array

Defined in

block.ts:421


isGenesis

isGenesis(): boolean

Determines if this block is the genesis block.

Returns

boolean

Defined in

block.ts:428


raw

raw(): BlockBytes

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

Returns

BlockBytes

Defined in

block.ts:403


serialize

serialize(): Uint8Array

Returns the rlp encoding of the block.

Returns

Uint8Array

Defined in

block.ts:435


toJSON

toJSON(): JsonBlock

Returns the block in JSON format.

Returns

JsonBlock

Defined in

block.ts:684


transactionsAreValid

transactionsAreValid(): boolean

Validates transaction signatures and minimum gas requirements.

Returns

boolean

True if all transactions are valid, false otherwise

Defined in

block.ts:520


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:452


uncleHashIsValid

uncleHashIsValid(): boolean

Validates the uncle's hash.

Returns

boolean

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

Defined in

block.ts:616


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:568


validateData

validateData(onlyHeader?): 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:

  • All transactions are valid
  • The transactions trie is valid
  • The uncle hash is valid

Parameters

Name Type Default value Description
onlyHeader boolean false if only passed the header, skip validating txTrie and unclesHash (default: false)

Returns

Promise<void>

Defined in

block.ts:535


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:677


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:643


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:626


fromBeaconPayloadJson

Static fromBeaconPayloadJson(payload, options?): 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
options? BlockOptions -

Returns

Promise<Block>

the block constructed block

Defined in

block.ts:349


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:86


fromExecutionPayload

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

Method to retrieve a block from an execution payload

Parameters

Name Type
payload ExecutionPayload
options? BlockOptions

Returns

Promise<Block>

the block constructed block

Defined in

block.ts:289


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:229


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:135


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 -

Returns

Block

Defined in

block.ts:218


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:151


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:72


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:59