Skip to content

Instantly share code, notes, and snippets.

@qianbin
Last active July 9, 2019 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qianbin/4e44bf9e8dde997c04c58fef461b95ee to your computer and use it in GitHub Desktop.
Save qianbin/4e44bf9e8dde997c04c58fef461b95ee to your computer and use it in GitHub Desktop.
calculate block number according to given time
// require connex-repl env
// calculate block number according to given time
async function whichBlock(targetTime) {
if(typeof targetTime === 'string') {
targetTime = new Date(targetTime).getTime()
}
return (await connex.thor.block().get()).number + Math.round((targetTime - Date.now()) / 1000 / 10)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment