date-to-block
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

Date To Block

This is a simple library for getting a block number based on a date using RPC calls.

The algorithm used is a simple binary search algorithm.

This library only supports viem and you need to provide a viem public client.

Installation

npm install date-to-block

Usage

First create a viem client:

import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";

const client = createPublicClient({
  chain: mainnet,
  transport: http(),
});

Then use date-to-block to get the block number:

import { dateToBlock } from "date-to-block";

const blockNumber = await dateToBlock(client, new Date("2021-01-01"));

Related work

Readme

Keywords

none

Package Sidebar

Install

npm i date-to-block

Weekly Downloads

522

Version

0.3.1

License

none

Unpacked Size

6.72 kB

Total Files

6

Last publish

Collaborators

  • larskarbo