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

Example of finding a nonce to solve Proof of Work

The following example will illustrate how to find a nonce by brute force, with the help of the SHA-256 algorithm, in order to find a hash value that will satisfy the target hash. The target hash value is determined by setting the difficulty bits in the Proof of Work algorithm. We will modify the blockchain linker that we created earlier on to include the Proof of Work algorithm while creating a new block. Firstly, let's modify a few functions of the blockchain example to include the consensus algorithm.

The Block class used to create a new block to be added to blockchain is modified to take two extra members, called difficulty_bits and nonce. We'll also include difficulty_bits in the header ...

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