0.0.6 • Published 4 years ago

eth-block-timestamp v0.0.6

Weekly downloads
36
License
-
Repository
-
Last release
4 years ago

Block by time

Get a block number by its date

NPM version Install Size

Demo -> https://blockbytime.com

Install

npm i eth-block-timestamp

Usage

import Blocks from 'eth-block-timestamp'

const blocks = new Blocks(
  (window as any).ethereum || 'https://mainnet.infura.io/v3/{API_KEY}'
)

// Get first block info
const { block, timestamp } = await blocks.getDate('first')

// Get latest block info
const { block, timestamp } = await blocks.getDate('latest')

// Get block info at 03/20/2020
const { block, timestamp } = await blocks.getDate('03/20/2020')

// Get block info at 03/20/2020 03:10:00 AM
const { block, timestamp } = await blocks.getDate('03/20/2020 03:10:00 AM')

// Get block info at 1586618608 (Unix Timestamp)
const { block, timestamp } = await blocks.getDate('1586618608')