BlockHeader class

The BlockHeader contains the metadata for the contents of a block, as well as data describing it's place/position in the blockchain.

The structure of the block header

4 bytes - Version - Block version number
32 bytes - hashPrevBlock - sha256 hash of the previous block header
32 bytes - hashMerkleRoot - sha256 hash at the root of a Merkle Tree.
4 bytes - Time - The current block timestamp as seconds since the unix epoch
4 bytes - Bits - The current difficulty target in compact format
4 bytes - Nonce - A 32-bit number (starts at 0)	A hash is tried (increments). A miner would change this field repeatedly as they attempt to generate a hash that matches the difficulty target.

Further notes on the block version number. See Bitcoin.org

  • Version 1 was introduced in the genesis block (January 2009).

  • Version 2 was introduced in Bitcoin Core 0.7.0 (September 2012) as a soft fork. As described in BIP34, valid version 2 blocks require a block height /parameter in the coinbase. Also described in BIP34 are rules for rejecting certain blocks; based on those rules, Bitcoin Core 0.7.0 and later versions began /to reject version 2 blocks without the block height in coinbase at block height 224,412 (March 2013) and began to reject new version 1 blocks three weeks /later at block height 227,930.

  • Version 3 blocks were introduced in Bitcoin Core 0.10.0 (February 2015) as a soft fork. When the fork reached full enforcement (July 2015), it required /strict DER encoding of all ECDSA signatures in new blocks as described in BIP66. Transactions that do not use strict DER encoding had previously been /non-standard since Bitcoin Core 0.8.0 (February 2012).

  • Version 4 blocks specified in BIP65 and introduced in Bitcoin Core 0.11.2 (November 2015) as a soft fork became active in December 2015. These blocks now support the new OP_CHECKLOCKTIMEVERIFY opcode described in that BIP.

Constructors

BlockHeader(int? _version, List<int>? _prevHash, List<int>? _merkleRoot, int? _time, int? _bits, int? _nonce)
Constructs a new block header
BlockHeader.fromBuffer(List<int> buffer)
Constructs a new block header from it's serialized byte array form
BlockHeader.fromHex(String blockHeaderHex)
Constructs a new block header from it's serialized hexadecimal form
BlockHeader.fromJSONMap(LinkedHashMap<String, dynamic> map)
Constructs a new block header from a structured object. This would typically be the result of parsing a JSON string using the dart:convert:jsonXXX API.
BlockHeader.fromRawBlock(List<int> dataRawBlockBinary)
Constructs a new block header from a raw block. A raw block would include the first 8 bytes for the magic number and block size fields

Properties

bits int?
Returns the block header's target difficulty
no setter
buffer List<int>
Returns this block header serialized in byte array form
no setter
hash List<int>
The double-sha256 of the serialized block header
no setter
hashCode int
The hash code for this object.
no setterinherited
id String
The block header's id is the same as it's hash property
no setter
merkleRoot List<int>?
Returns the byte buffer representing the sha256 hash of the transaction merkle root
no setter
nonce int?
Returns the block header's nonce value
getter/setter pair
prevHash List<int>?
Returns the sha256 hash of the previous block header
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
time int?
Returns the timestamp for this block header. Time is in seconds since unix epoch.
getter/setter pair
version int?
Returns the block header
no setter

Methods

getDifficulty() double
Returns the difficulty target of this block header
getTargetDifficulty({int? targetBits = null}) BigInt
Returns current difficulty target or calculates a specific difficulty target.
hasValidProofOfWork() bool
Returns true if the sha256 hash of the block header matches the difficulty target, false otherwise.
hasValidTimestamp() bool
Returns true if the timestamp is smaller than the BlockHeader.MAX_TIME_OFFSET, false otherwise.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toHex() String
Renders/Serializes the block header to a hexadecimal string
toJSON() String
Renders/Serializes the block header to a JSON string
toObject() Map<String, dynamic>
Renders/Serializes the block header to a structured object
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

GENESIS_BITS int
Difficulty target at genesis
final
LARGEST_HASH BigInt
The largest size a hash value could possibly be
final
MAX_TIME_OFFSET int
The max a timestamp can be in the future
final
START_OF_HEADER int
Byte offset denoting start of the header data structure
final