Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

block-at-timestamp

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

block-at-timestamp

Quickly find a block close to a target timestamp using an RPC URL or ethers Provider.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

block-at-timestamp

version typescript ethers

Quickly find a block close to a target timestamp using an RPC URL or ethers Provider.

Installation

Install the package with the following command:

npm i block-at-timestamp

Usage

Example Usage:

import { blockAtTimestamp } from "block-at-timestamp";

let timestamp = 1674420070; // unix timestamp in seconds
let block = await blockAtTimestamp("https://rpc-provider.example/", timestamp);

Optional Target Range:

By default, the algorithm will attempt to find a block within 60 seconds of the target timestamp. If you want a faster result with less accuracy, you can increase the targetRangeSeconds parameter like so:

await blockAtTimestamp(provider, timestamp, {
  targetRangeSeconds: 60 * 60 // one hour
});

Debugging:

To see logs for debugging purposes, you can enable verbose logging with the following:

import { setVerbose } from "block-at-timestamp";

setVerbose(true);

Keywords

FAQs

Package last updated on 20 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc