Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nachomazzara/eth-block-timestamp
Get Block by timestamp
https://github.com/nachomazzara/eth-block-timestamp
ethereum evm web3
Last synced: 4 days ago
JSON representation
Get Block by timestamp
- Host: GitHub
- URL: https://github.com/nachomazzara/eth-block-timestamp
- Owner: nachomazzara
- Created: 2020-03-13T20:21:35.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T02:31:28.000Z (almost 2 years ago)
- Last Synced: 2023-04-10T18:52:01.605Z (over 1 year ago)
- Topics: ethereum, evm, web3
- Language: TypeScript
- Homepage: https://blockbytime.com
- Size: 4.02 MB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Block by time
> Get a block number by its date
[![NPM version](https://badge.fury.io/js/eth-block-timestamp.svg)](https://npmjs.org/package/eth-block-timestamp@latest)
[![Install Size](https://packagephobia.now.sh/badge?p=eth-block-timestamp@latest)](https://packagephobia.now.sh/result?p=eth-block-timestamp@latest)## Demo -> https://blockbytime.com
## Install
```bash
npm i eth-block-timestamp
```### Usage
```typescript
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')
```