SHA256 Hash Function

Pubblicato il: 30 novembre 2020
sul canale di: The Library Of Knowledge
384
2

Hi SUBSCRIBE for more insane value!

Hello and welcome to this course on building a blockchain and a cryptocurrency. By the end of this course, you will know how blockchains work at the core, and how cryptocurrencies like Bitcoin are implemented.

The next few videos introduce the core concepts of the Blockchain and cryptocurrencies. You will find them helpful if you want a more well-rounded understanding of the main features of both the blockchain and cryptocurrencies.

The code starts in the next section. But I recommend watching these introductory videos in order to see the main concepts that we’ll be focusing on when it comes to building blockchains and cryptocurrencies.

Alright, let’s get to it!

A hashing function generates a unique value for the combination of data attributes in the block. The hash for a new block is based on its own timestamp, the data it stores, and the hash of the block that came before it.

Install the `crypto-js` module which has the SHA256 (Secure Hashing Algorithm 256-bit) function:
$ npm i crypto-js --save

In block.js, require the sha256 from the `crypto-js` module at the top:
```
const SHA256 = require('crypto-js/sha256');
```

Then add a new static hash function to the Block class:
```
static hash(timestamp, lastHash, data) {
return SHA256(`${timestamp}${lastHash}${data}`).toString();
}
```

Now replace the ‘todo-hash’ stub in the `mineBlock` function:
```
const hash = Block.hash(timestamp, lastHash, data);
```

Check the command line - `npm run dev-test` should still be running. Notice the generated hash of the block.


In questa pagina del sito puoi guardare il video online SHA256 Hash Function della durata di ore minuti seconda in buona qualità , che l'utente ha caricato The Library Of Knowledge 30 novembre 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 384 volte e gli è piaciuto 2 spettatori. Buona visione!