0.3.1 • Published 2 months ago

date-to-block v0.3.1

Weekly downloads
-
License
-
Repository
github
Last release
2 months ago

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

0.3.0

2 months ago

0.3.1

2 months ago

0.2.0

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago