@ethereumjs/block › "index" › Block
An object that represents the block.
- Block
- canonicalDifficulty
- genTxTrie
- hash
- isGenesis
- raw
- serialize
- toJSON
- validate
- validateData
- validateDifficulty
- validateGasLimit
- validateTransactions
- validateTransactionsTrie
- validateUncles
- validateUnclesHash
- fromBlockData
- fromRLPSerializedBlock
- fromValuesArray
- genesis
+ new Block(header?
: BlockHeader, transactions
: Transaction[], uncleHeaders
: BlockHeader[], opts
: BlockOptions): Block
Defined in block.ts:107
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 |
---|---|---|
header? |
BlockHeader | - |
transactions |
Transaction[] | [] |
uncleHeaders |
BlockHeader[] | [] |
opts |
BlockOptions | {} |
Returns: Block
• _common: Common
Defined in block.ts:18
• header: BlockHeader
Defined in block.ts:14
• transactions: Transaction[] = []
Defined in block.ts:15
• txTrie: Trie‹› = new Trie()
Defined in block.ts:17
• uncleHeaders: BlockHeader[] = []
Defined in block.ts:16
▸ canonicalDifficulty(parentBlock
: Block): BN
Defined in block.ts:307
Returns the canonical difficulty for this block.
Parameters:
Name | Type | Description |
---|---|---|
parentBlock |
Block | the parent of this Block |
Returns: BN
▸ genTxTrie(): Promise‹void›
Defined in block.ts:168
Generates transaction trie for validation.
Returns: Promise‹void›
▸ hash(): Buffer
Defined in block.ts:147
Produces a hash the RLP of the block.
Returns: Buffer
▸ isGenesis(): boolean
Defined in block.ts:154
Determines if this block is the genesis block.
Returns: boolean
▸ raw(): BlockBuffer
Defined in block.ts:136
Returns a Buffer Array of the raw Buffers of this block, in order.
Returns: BlockBuffer
▸ serialize(): Buffer
Defined in block.ts:161
Returns the rlp encoding of the block.
Returns: Buffer
▸ toJSON(): JsonBlock
Defined in block.ts:333
Returns the block in JSON format.
Returns: JsonBlock
▸ validate(blockchain
: Blockchain): Promise‹void›
Defined in block.ts:229
Performs the following consistency checks on the block:
- Value checks on the header fields
- Signature and gasLimit validation for included txs
- Validation of the tx trie
- Consistency checks and header validation of included uncles
Throws if invalid.
Parameters:
Name | Type | Description |
---|---|---|
blockchain |
Blockchain | validate against a @ethereumjs/blockchain |
Returns: Promise‹void›
▸ validateData(): Promise‹void›
Defined in block.ts:242
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
Returns: Promise‹void›
▸ validateDifficulty(parentBlock
: Block): boolean
Defined in block.ts:316
Checks that the block's difficulty
matches the canonical difficulty.
Parameters:
Name | Type | Description |
---|---|---|
parentBlock |
Block | the parent of this Block |
Returns: boolean
▸ validateGasLimit(parentBlock
: Block): boolean
Defined in block.ts:326
Validates if the block gasLimit remains in the boundaries set by the protocol.
Parameters:
Name | Type | Description |
---|---|---|
parentBlock |
Block | the parent of this Block |
Returns: boolean
▸ validateTransactions(): boolean
Defined in block.ts:201
Validates transaction signatures and minimum gas requirements.
Returns: boolean
▸ validateTransactions(stringError
: false): boolean
Defined in block.ts:202
Parameters:
Name | Type |
---|---|
stringError |
false |
Returns: boolean
▸ validateTransactions(stringError
: true): string[]
Defined in block.ts:203
Parameters:
Name | Type |
---|---|
stringError |
true |
Returns: string[]
▸ validateTransactionsTrie(): Promise‹boolean›
Defined in block.ts:182
Validates the transaction trie by generating a trie and do a check on the root hash.
Returns: Promise‹boolean›
▸ validateUncles(blockchain
: Blockchain): Promise‹void›
Defined in block.ts:283
Consistency checks and header validation for uncles included, in the block, if any.
Throws if invalid.
The rules of uncles are the following: Uncle Header is a valid header. Uncle Header is an orphan, i.e. it is not one of the headers of the canonical chain. Uncle Header has a parentHash which points to the canonical chain. This parentHash is within the last 7 blocks. Uncle Header is not already included as uncle in another block. Header has at most 2 uncles. Header does not count an uncle twice.
Parameters:
Name | Type | Description |
---|---|---|
blockchain |
Blockchain | additionally validate against an @ethereumjs/blockchain instance |
Returns: Promise‹void›
▸ validateUnclesHash(): boolean
Defined in block.ts:262
Validates the uncle's hash.
Returns: boolean
▸ fromBlockData(blockData
: BlockData, opts?
: BlockOptions): Block‹›
Defined in block.ts:20
Parameters:
Name | Type | Default |
---|---|---|
blockData |
BlockData | {} |
opts? |
BlockOptions | - |
Returns: Block‹›
▸ fromRLPSerializedBlock(serialized
: Buffer, opts?
: BlockOptions): Block‹›
Defined in block.ts:53
Parameters:
Name | Type |
---|---|
serialized |
Buffer |
opts? |
BlockOptions |
Returns: Block‹›
▸ fromValuesArray(values
: BlockBuffer, opts?
: BlockOptions): Block‹›
Defined in block.ts:63
Parameters:
Name | Type |
---|---|
values |
BlockBuffer |
opts? |
BlockOptions |
Returns: Block‹›
▸ genesis(blockData
: BlockData, opts?
: BlockOptions): Block‹›
Defined in block.ts:104
Alias for Block.fromBlockData() with initWithGenesisHeader set to true.
Parameters:
Name | Type | Default |
---|---|---|
blockData |
BlockData | {} |
opts? |
BlockOptions | - |
Returns: Block‹›