For a given lease period, how can we know when the lease period starts and ends (as date time)?

1 Answer 1


On Kusama and Polkadot - Given a lease period "x", you will need to retrieve the storage constants slots.leasePeriod and slots.leaseOffset. Then compute the height at which the lease period start this way :

x*leasePeriod + leaseOffset

And its end

(x+1)*leasePeriod + leaseOffset -1

Once you have the heightStart and heightEnd of your lease period "x", retrieve the head block (for example with api.rpc.chain.getBlock();).

If heightStart is lower or equal than the head block height, then retrieve the block which number is equal to heightStart (first by getting its hash blockStartHash = this.api.rpc.chain.getBlockHash(heightStart);, then by getting the block using the hash : startBlock = api.rpc.chain.getBlock(blockStartHash);. Now you have the timestamp (from startBlock properties) of the of the start of the lease period. You can do the same for the heightEnd.

If the heightStart or heightEnd is greater than the headBlock's number (height), then it is possible to estimate the timestamp of the lease period start (and/or end). To do so, you get the difference between the height and the head block's height. For example diffBlock = heightStart - headBlockHeight then multiple that value with the MILLISECS_PER_BLOCK constant value of the chain (for both Polkadot and Kusama it is 6000) and finally add it to the head block's timestamp to have a your estimatedLeasePeriodStartTimestamp (or ...End...).


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.