5

How to obtain block/slot time?

I know that I can view it here under the 1min and 1hr Slot Time average, but what I'm after is a way to request it directly via the Solana-web3js library or the JSON-RPC library. Is there a way?

Also I'm after the time it takes to process the block, not the block timestamp

thanks

2 Answers 2

2

You can use the RPC method getRecentPerformanceSamples: https://docs.solana.com/developing/clients/jsonrpc-api#getrecentperformancesamples

It gives a result like this:

[
    {
      "numSlots": 126,
      "numTransactions": 126,
      "samplePeriodSecs": 60,
      "slot": 348125
    },
    ...
]

So I think the 1 min calculation is that the slot time (in seconds) is samplePeriodSecs/numSlots

That API can return multiple samples (up to 720), so for example for the 1 hour average you could pass limit=60, do the above calculation for each sample and average them out.

1
  • samplePeriodSecs/numSlots = 60/126 = 476ms, or 2.1 slots per second. Commented Nov 14, 2023 at 10:42
0
async function getBlockTime() {
  let absoluteSlot = (await connection.getEpochInfo()).absoluteSlot;
  return await connection.getBlockTime(absoluteSlot);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.