A Node.js script retrieves the starting and ending Ethereum block numbers for a given UTC date by querying the Etherscan API endpoint getblocknobytime
.
- Fetch the first block at or after 00:00:00 UTC of a specified date
- Fetch the last block at or before 23:59:59 UTC of a specified date
- Uses
axios
for HTTP requests andmoment
for date handling
- Node.js v12 or higher
- An Etherscan API key (free to register at https://etherscan.io/apis)
- Clone or download this repository.
- Install dependencies:
npm install
Run the script with three arguments: the start date, end date in YYYY-MM-DD
format and your Etherscan API key.
node script/getBlock-etherScan.js