Target

everything you need to know about how to handle target and difficulty

Here is an example of the whole process to go from a difficulty to the corresponding target to send to miners.

1. Convert difficulty to target:

Here is a code example of how to convvert a difficulty to target For instance a difficulty of 50000 would return a target of 2315841784746323908471419700173758157065399693312811280789151680158262592

static getTargetFromDifficulty(difficulty)
    {

      console.log(' getTargetFromDifficulty() difficulty:', web3utils.toBN( difficulty).toString());
    
      var max_target = web3utils.toBN('2').pow(web3utils.toBN('256')).sub(web3utils.toBN('1'));

      const difficultyBN = web3utils.toBN(difficulty);
 
      var current_target = max_target.div(difficultyBN);

      console.log(' getTargetFromDifficulty() current_target:',  current_target.toString());
 
      return current_target ;
    } 

2. Then convert target in hex format:

3. Convert target to miner expected format:

Example in code use:

Last updated