Skip to content
  • Home
  • Privacy Policy
  • Services
  • Testimonials
  • Who we are
  • Blog
  • Let’s Talk

Zuiver

  • Let’s Talk
  • Toggle search form

Ethereum: How Proof of Work Algorithm works?

Posted on July 28, 2022July 28, 2022 By admin No Comments on Ethereum: How Proof of Work Algorithm works?

When you are at the learning stage in Ethereum, definitely this would have been buzz word and more frequently people use the word “POW”. Though it looks simple to understand from a theory standpoint, but not actually when you relate this with mining the transactions. In this article, I just want to explain how this works with a very nice programming concept I inspired from Udemy Course.

Let’s consider, that you are submitting a transaction with some data, as soon as you submit, the Tx(transaction) will be lined up in the queue for mining which miners will have to perform some puzzle cracking game and figure out your transaction is valid or not, but how they are doing that? how does it actually work behind the scene? is a mystery(if you don’t understand). Let’s crack that mystery now.

I have a data “HelloWorld”, as soon as I submit the transaction the encryption algorithm (SHA256) will be applied and a Tx Hash will be generated. Usually, txHash will contain leading zeros (prefixed). Prediction of this leading zero’s is the game for Miners. What?, are you serious? I read your mind. Yes, this seems easy but actually a very time & power-consuming process. Since the leading zeros are not static and it changes from transaction to transaction, we call it “Difficulty”. When miners figure out the leading zeros well before the average time, then the difficulty level auto adjusted for the next transaction, thus miners will always have a tough time figuring out this.

How does it work?

Let’s say my txHash is 0000000000001x2xhf2sdkfhsdfh2ksdfhksdfhsdf (rough value)

below function solves the purpose,

function puzzle(data,prefix){
var nonce = ‘NOT-FOUND’;
var start = DATE.now();
var end = start;

for(tryNonce = 0; tryNonce < 1000000000; tryNonce++){
var y = blockdata + tryNonce;
var sha = SHA256(y);

if(sha.startsWith(prefix)){
var end = Date.now();
nonce = tryNonce;
console.log(SHA256(blockdata + tryNonce));
break;
}
}
var timetaken = end — start;
if(timetaken ==0)
{
console.log(“not found”);
}else{
console.log(“Prefix”, prefix, “TimeTaken”, timetaken);
}

}

var data = “helloworld”;

puzzle(data,”0″);
puzzle(data,”00″);
puzzle(data,”000″);
puzzle(data,”0000″);
puzzle(data,”00000″);
puzzle(data,”000000″);
puzzle(data,”0000000″);
puzzle(data,”00000000″);

How puzzle function works?

> it runs through the loop and add the “tryNonce” with “data” we provided and create hash key using SHA256

> Verify if generated hash key is starting with the “prefix” we passed as a parameter.

> it breaks and come out of loop if it finds the prefix and that’s the NONCE value to be added in TxN (Nonce -> number used once)

> So more the prefix value, higher number of loop will executes, this will consume more energy

This is the reason, why miners are being paid a small transaction fee, they spend time & energy(power) to figure out whether the transaction is valid or not.

Thanks for taking a min to read this article, hope you got some clarity on how POW works?, if not put your questions in comment section below.

Tags:amazon hiring digital currency blockchain lead, argo blockchain nasdaq, avalanche blockchain, azure blockchain service mayfoleyzdnet, azure blockchain service september mayfoleyzdnet, best blockchain stocks, blockchain aktie, blockchain api, blockchain architecture, blockchain as a service, blockchain books, blockchain capital, blockchain consulting, blockchain database, blockchain developer roadmap, blockchain domain, blockchain erklärung, blockchain ethereum, blockchain foundry aktie, blockchain investment, blockchain real estate, blockchain reliability, blockchain significado, blockchain space, blockchain technology ppt, blockchain whispers, blockchain wiki, blockchain wormhole therecord, blockchain คืออะไร, công nghệ blockchain, core scientific 545m riot blockchain 215m, cosmos blockchain, etf blockchain, ganache blockchain, how is blockchain different from traditional database models, htc pivots from blockchain to metaverse, ibm blockchain cuts is shell its, ibm blockchain job cuts is shell, la blockchain, microsoft azure blockchain mayfoleyzdnet, microsoft azure blockchain service mayfoleyzdnet, microsoft azure blockchain service september, ni no kuni cross worlds blockchain, proof of work blockchain, quotazione riot blockchain, report core 545m riot blockchain 215m, report core scientific 545m blockchain 215m, report core scientific riot blockchain 215m, report scientific 545m riot blockchain 215m, riot blockchain quotazione, strange allure blockchain, the allure blockchain, the blockchain, top blockchain games, valereum blockchain share price, war of ants - blockchain game, what is blockchain developer, what's a blockchain, which model describes how data is written to a blockchain, which statement describes data-sharing in a blockchain

Post navigation

Previous Post: Step by Step Approach to create DAPP—using Ethereum, ReactJS & IPFS — Part 1
Next Post: Hyperledger Developer — Road Map

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2022 Zuiver. Sources: Top Blockchain Companies-Top Blockchain development Tools-Top Blockchain Platforms

Powered by PressBook Grid Dark theme