Skip to content

Instantly share code, notes, and snippets.

@oldgitdaddy
Last active June 14, 2019 16:11
Show Gist options
  • Select an option

  • Save oldgitdaddy/086500d35b34c0bf38f8424b4d42522f to your computer and use it in GitHub Desktop.

Select an option

Save oldgitdaddy/086500d35b34c0bf38f8424b4d42522f to your computer and use it in GitHub Desktop.
function proof_of_work(difficulty, prev_hash, timestamp, merkle_root) {
var hash = “1111111111111111111111111111111111111111111111111111111111111111”;
var nonce = 0;
//check if hash meets difficulty criteria (by counting number of zeros)
while (hash.substring(0, difficulty) !== Array(difficulty + 1).join("0")) {
//incrementing the nonce value every time the loop runs.
nonce++;
//recalculating the hash value
hash = this.calculateHash(nonce, prev_hash, timestamp, merkle_root);
}
console.log("Block mined: " + hash)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment