Created
February 13, 2020 21:31
-
-
Save madoke/81bdd5a1fd35680df39ae4e28f8e0d7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const fs = require('fs'); | |
const hash = (block) => { | |
const json = JSON.stringify(block); | |
const hash = crypto.createHash('sha256'); | |
hash.update(json); | |
return hash.digest('hex'); | |
} | |
const block = { | |
id: "some_id", | |
data: "some_data", | |
nonce: 0 | |
}; | |
while(true) { | |
const block_hash = hash(block); | |
console.log(block_hash); | |
if(block_hash.startsWith('0')) { | |
console.log("Proof of Work Found !") | |
break; | |
} | |
block.nonce += 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment