@ethereumjs/block / Block
An object that represents the block.
- errorStr
- ethashCanonicalDifficulty
- genTxTrie
- getTransactionsValidationErrors
- hash
- isGenesis
- raw
- serialize
- toJSON
- transactionsAreValid
- transactionsTrieIsValid
- uncleHashIsValid
- validateBlobTransactions
- validateData
- validateGasLimit
- validateUncles
- withdrawalsTrieIsValid
- fromBeaconPayloadJson
- fromBlockData
- fromExecutionPayload
- fromJsonRpcProvider
- fromRLPSerializedBlock
- fromRPC
- fromValuesArray
- genTransactionsTrieRoot
- genWithdrawalsTrieRoot
• 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.
Name | Type | Default value |
---|---|---|
header? |
BlockHeader |
undefined |
transactions |
TypedTransaction [] |
[] |
uncleHeaders |
BlockHeader [] |
[] |
withdrawals? |
Withdrawal [] |
undefined |
opts |
BlockOptions |
{} |
executionWitness? |
null | VerkleExecutionWitness |
undefined |
• Readonly
common: Common
• 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
• Readonly
header: BlockHeader
• Readonly
transactions: TypedTransaction
[] = []
• Readonly
uncleHeaders: BlockHeader
[] = []
• Optional
Readonly
withdrawals: Withdrawal
[]
▸ errorStr(): string
Return a compact error string representation of the object
string
▸ ethashCanonicalDifficulty(parentBlock
): bigint
Returns the canonical difficulty for this block.
Name | Type | Description |
---|---|---|
parentBlock |
Block |
the parent of this Block |
bigint
▸ genTxTrie(): Promise
<Uint8Array
>
Generates transaction trie for validation.
Promise
<Uint8Array
>
▸ getTransactionsValidationErrors(): string
[]
Validates transaction signatures and minimum gas requirements.
string
[]
an array of error strings
▸ hash(): Uint8Array
Returns the hash of the block.
Uint8Array
▸ isGenesis(): boolean
Determines if this block is the genesis block.
boolean
▸ raw(): BlockBytes
Returns a Array of the raw Bytes Arrays of this block, in order.
▸ serialize(): Uint8Array
Returns the rlp encoding of the block.
Uint8Array
▸ toJSON(): JsonBlock
Returns the block in JSON format.
▸ transactionsAreValid(): boolean
Validates transaction signatures and minimum gas requirements.
boolean
True if all transactions are valid, false otherwise
▸ transactionsTrieIsValid(): Promise
<boolean
>
Validates the transaction trie by generating a trie and do a check on the root hash.
Promise
<boolean
>
True if the transaction trie is valid, false otherwise
▸ uncleHashIsValid(): boolean
Validates the uncle's hash.
boolean
true if the uncle's hash is valid, false otherwise.
▸ 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
Name | Type | Description |
---|---|---|
parentHeader |
BlockHeader |
header of parent block |
void
▸ 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:
- All transactions are valid
- The transactions trie is valid
- The uncle hash is valid
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) |
Promise
<void
>
▸ validateGasLimit(parentBlock
): void
Validates if the block gasLimit remains in the boundaries set by the protocol. Throws if invalid
Name | Type | Description |
---|---|---|
parentBlock |
Block |
the parent of this Block |
void
▸ 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.
void
▸ withdrawalsTrieIsValid(): Promise
<boolean
>
Validates the withdrawal root
Promise
<boolean
>
true if the withdrawals trie root is valid, false otherwise
▸ Static
fromBeaconPayloadJson(payload
, opts?
): Promise
<Block
>
Method to retrieve a block from a beacon payload json
Name | Type | Description |
---|---|---|
payload |
BeaconPayloadJson |
json of a beacon beacon fetched from beacon apis |
opts? |
BlockOptions |
BlockOptions |
Promise
<Block
>
the block constructed block
▸ Static
fromBlockData(blockData?
, opts?
): Block
Static constructor to create a block from a block data dictionary
Name | Type |
---|---|
blockData |
BlockData |
opts? |
BlockOptions |
▸ Static
fromExecutionPayload(payload
, opts?
): Promise
<Block
>
Method to retrieve a block from an execution payload
Name | Type | Description |
---|---|---|
payload |
ExecutionPayload |
- |
opts? |
BlockOptions |
BlockOptions |
Promise
<Block
>
the block constructed block
▸ Static
fromJsonRpcProvider(provider
, blockTag
, opts
): Promise
<Block
>
Method to retrieve a block from a JSON-RPC provider and format as a Block
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 |
Promise
<Block
>
the block specified by blockTag
▸ Static
fromRLPSerializedBlock(serialized
, opts?
): Block
Static constructor to create a block from a RLP-serialized block
Name | Type |
---|---|
serialized |
Uint8Array |
opts? |
BlockOptions |
▸ Static
fromRPC(blockData
, uncles?
, opts?
): Block
Creates a new block object from Ethereum JSON RPC.
Name | Type | Description |
---|---|---|
blockData |
JsonRpcBlock |
- |
uncles? |
any [] |
Optional list of Ethereum JSON RPC of uncles (eth_getUncleByBlockHashAndIndex) |
opts? |
BlockOptions |
An object describing the blockchain |
▸ Static
fromValuesArray(values
, opts?
): Block
Static constructor to create a block from an array of Bytes values
Name | Type |
---|---|
values |
BlockBytes |
opts? |
BlockOptions |
▸ Static
genTransactionsTrieRoot(txs
, emptyTrie?
): Promise
<Uint8Array
>
Returns the txs trie root for array of TypedTransaction
Name | Type | Description |
---|---|---|
txs |
TypedTransaction [] |
array of TypedTransaction to compute the root of |
emptyTrie? |
Trie |
- |
Promise
<Uint8Array
>
▸ Static
genWithdrawalsTrieRoot(wts
, emptyTrie?
): Promise
<Uint8Array
>
Returns the withdrawals trie root for array of Withdrawal.
Name | Type | Description |
---|---|---|
wts |
Withdrawal [] |
array of Withdrawal to compute the root of |
emptyTrie? |
Trie |
- |
Promise
<Uint8Array
>