Skip to content

Instantly share code, notes, and snippets.

@madoke
Created February 13, 2020 21:31
Show Gist options
  • Save madoke/81bdd5a1fd35680df39ae4e28f8e0d7c to your computer and use it in GitHub Desktop.
Save madoke/81bdd5a1fd35680df39ae4e28f8e0d7c to your computer and use it in GitHub Desktop.
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