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'),
true,
false
)
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.