# All files / src/utils getBlockAverageTime.js

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

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

    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;