# All files / src/utils getBlockAverageTime.js

100% Statements 7/7
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    101x
    5x
    5x
    5x
    5x
    5x

    1x
     const getBlockAverageTime = async web3 => {
      const span = 40000;
      const blockNumber = await web3.eth.getBlockNumber();
      const b1 = await web3.eth.getBlock(blockNumber);
      const b2 = await web3.eth.getBlock(Math.max(0, blockNumber - span));
      return (b1.timestamp - b2.timestamp) / (b1.number - b2.number);
    };

    module.exports = getBlockAverageTime;