Sort:  

Thank you for sharing your posts with us. This post was curated by TeamMalaysia as part of our community support. Looking forward for more posts from you.

To support the growth of TeamMalaysia Follow our upvotes by using steemauto.com and follow trail of @myach

Vote TeamMalaysia witness bitrocker2020 using this link vote bitrocker2020 witness

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank you moderator, really appreciate it 🙌

Hey @superoo7 I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Great tutorial, was easy to understand for a novice TypeScript coder.

You can use nodejs built in hashing library for making the sha256 hash so no need to import js-sha256 libraries ;)

var crypto = require('crypto');
var hash = crypto.createHash('sha256').update(block.key).digest("hex");

here is my complete generateHash method:

public generateHash(block: BlockData): string {
    let hash = crypto.createHash('sha256').digest("hex");
    
    // mining
    while(!hash.startsWith(Array(this.difficulty + 1).join('0'))) {
        block.nonce += 1;
        hash = crypto.createHash('sha256').update(block.key).digest("hex");
        console.log(block.nonce, hash);
    }

    return hash;
}

I din know that, was finding a library which supporr types haha. Thanks for sharing about this.