SHA256 Hash Function

Publicado el: 30 noviembre 2020
en el canal de: 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.


En esta página del sitio puede ver el video en línea SHA256 Hash Function de Duración hora minuto segunda en buena calidad , que subió el usuario The Library Of Knowledge 30 noviembre 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 384 veces y le gustó 2 a los espectadores. Disfruta viendo!