1

I'm looking for a reliable way to determine when the block was produced by given any block number in Polygon Mumbai Testnet. I can't use Api for this task . I'm just looking for a convenient way of computing. Do you have any suggestion for this?

1 Answers1

0

I definitely recommend invoking APIs, however, given your heavy requirement on NoAPIs, we'd have to go with estimates.

In this case -

  • First, we need to find the average time per block. Polygon takes approximately - 2.5s to generate a new block - Data
  • Then you'd need to identify the number of blocks that have already been generated (manual input in this case)
    • At the time of writing this answer - 36996889 blocks have been generated.
  • Finally, you need the block number you want to get the time estimate for.
    • let's take 36996800 as an example in this case.

So, to identify the estimates (again, not accurate at all) you can use the following algorithm.

const currentBlockNumber = 36996889; 
const targetBlockNumber = 36996800; 
const averageTimePerBlock = 2.5;

// Get the numenr of blocks that have been produced sinve the target block you're trying to estimate for
const numberOfBlocks = currentBlockNumber - targetBlockNumber;

// Calculate the approximate time that the target block was produced at
const approximateTimeInSeconds = numberOfBlocks * averageTimePerBlock;

// Calculate the approximate date and time that the target block was produced
const dateAndTimeCurrentBlockWasProducedAt = new Date(1671405095000); // This was the epoch currentBlock was produced at
const approximateTimeInMilliseconds = dateAndTimeCurrentBlockWasProducedAt.getTime() - (approximateTimeInSeconds * 1000); // get approx epoch for targetBlock
const approximateDate = new Date(approximateTimeInMilliseconds); // convert approxTime to human readable date

console.log(`The target block was produced approximately on ${approximateDate}.`);