Bitcoin is commonly thought about as a ledger of transactions. Let's use that as a starting point.

Headers

We group the transactions into 'blocks'. Each block starts with a header, with information on the block's contents:

Hash = bytes

VERSION: int = 0

def init_header(previous_hash: Hash, timestamp: int, nonce: int) -> bytes:
    """ """
    return (
        VERSION.to_bytes(1, byteorder="big")
        + previous_hash
        + timestamp.to_bytes(4, byteorder="big")
        + nonce.to_bytes(32, byteorder="big")
    )

We use 'hash' as both a verb (to hash something) and a noun (the output of a hash function). It's a little confusing. To help clear things up, let's do something concrete - we solve for the nonce and create our first block.

Since there is no previous block, the previous hash is set to zero. We choose an arbitrary timestamp and initialize the nonce to zero. The header now looks like this.

previous_hash = (0).to_bytes(32, byteorder="big")
timestamp = 1634700000
nonce = 0

header = init_header(previous_hash, timestamp, nonce)
print(f"header:\\n{header}")
header:
b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00ao\\x8a\\xe0\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'

We can make the header more readable by limiting each line to 16 bytes and separating each byte with a dash delimiter.

import binascii

def prettify(b: bytes) -> str:
    """ """
    n = len(b)
    m = (n // 16) + (n % 16 > 0)

    result = [
        binascii.hexlify(b[i * 16 : (i + 1) * 16], sep="-").decode()
        for i in range(m)
    ]
    return "\\n".join(result)

print(f"header:\\n{prettify(header)}")
header:
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
00-61-6f-8a-e0-00-00-00-00-00-00-00-00-00-00-00
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
00-00-00-00-00