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

1.0.2 • Public • Published

Ethereum Block By Date

Get Ethereum block number by a given date, using viem.

Installation

bun i eth-block-for-date

Usage

import EthDater from 'eth-block-for-date'
import { createPublicClient, http } from 'viem'

const client = createPublicClient({ transport: http('YOUR_RPC_URL') })
const dater = new EthDater(client)

let block = await dater.getDate(
	new Date('2016-07-20T13:20:40Z'), // Date, required.
	true, // Block after, optional. Search for the nearest block before or after the given date. True by default.
	false // Refresh boundaries, optional. Recheck the latest block before request. False by default
)

If the given date is in the future, the script will return the latest block.

License

This project is licensed under the MIT License. Check the License file for more info.

Package Sidebar

Install

npm i eth-block-for-date

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

32.1 kB

Total Files

12

Last publish

Collaborators

  • m1guelpiedrafita