Skip to Content
Foundations of Blockchain
book

Foundations of Blockchain

by Koshik Raj
January 2019
Beginner to intermediate
372 pages
11h 17m
English
Packt Publishing
Content preview from Foundations of Blockchain

Block structure

Let's consider a simple block whose header and data are combined to create a data structure called Block. Each Block will contain the following: an index, the previous hash, a timestamp, data, and its own hash value:

class Block(object): 
    """A class representing the block for the blockchain""" 
 
    def __init__(self, index, previous_hash, timestamp, data, hash): 
        self.index = index 
        self.previous_hash = previous_hash 
        self.timestamp = timestamp 
        self.data = data 
        self.hash = hash 

The preceding code snippet defines a Python class called Block that has all the basic attributes of a blockchain block. Usually, a block will contain both a header and a body, with the header containing metadata about the block. However, the preceding example ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Blockchain Basics

Blockchain Basics

Daniel Drescher
What Is Blockchain?

What Is Blockchain?

Sir John Hargrave, Evan Karnoupakis
Mastering Blockchain

Mastering Blockchain

Lorne Lantz, Daniel Cawrey

Publisher Resources

ISBN: 9781789139396Supplemental Content