[英]Block time calculation by block number in Polygon Mumbai Testnet
我正在尋找一種可靠的方法來確定該塊何時由 Polygon Mumbai Testnet 中給定的任何塊號生成。 我不能將 Api 用於此任務。 我只是在尋找一種方便的計算方式。 你對此有何建議?
我絕對建議調用 API,但是,鑒於您對NoAPIs
的大量要求,我們必須進行估算。
在這種情況下 -
2.5s
來生成一個新塊 -數據36996889
個塊。36996800
為例。因此,要確定估計值(同樣,一點也不准確),您可以使用以下算法。
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}.`);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.