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

Ethers Provider extension to quickly find a block close to a target timestamp.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

block-at-timestamp

version typescript ethers

Ethers Provider extension to quickly find a block close to a target timestamp.

Installation

Install the package with the following command:

npm i block-at-timestamp

Usage

Example Usage:

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

let provider = new ethers.providers.JsonRpcProvider("https://rpc-provider.example/");
let timestamp = 1674420070; // unix timestamp in seconds
let block = await blockAtTimestamp(provider, 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 24 Jan 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