Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PROVIDER=""
INFURA_API_KEY=""
33 changes: 33 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ethereum Block By Date

Get Ethereum block number by a given date. Or blocks by a given period duration.
Get Ethereum block number by a given date. blocks by a given period duration. or date from a given block

Works with any Ethereum based mainnet or testnet networks.

Expand Down Expand Up @@ -113,7 +113,7 @@ let requests = dater.requests;
/* Returns a count of made requests */
```

Note: if the given date is before the first block date in the blockchain, the script will return 1 as block number. If the given date is in the future, the script will return the last block number in the blockchain.
Note: if the given date is before the first block date in the blockchain, the script will return 1 as block number. If the given date is in the future, the script will return the last block number in the blockchain. if the given block is less than the latest block, the script will return the actual timestamp of the given block. If the given block is in the future, the script will return estimated timestamp.

## Moment.js

Expand Down Expand Up @@ -164,6 +164,18 @@ let blocks = await dater.getEvery('hours', '2019-10-10T00:00:00Z', '2019-10-11T0
] */
```

Get estimate timestamp of future block:
```javascript
let futureBlock = 4294967295;
let timestamp = await dater.getEstimateDate(futureBlock);

/* Returns an object: {
date: '3785-06-26T22:32:33Z', // estimated date
block: 4294967295, // given block number
timestamp: 57291229953 // estimated block timestamp
*/
```

## Need Help

If you need any help, please contact me via GitHub issues page: [GitHub](https://github.com/monosux/ethereum-block-by-date/issues)
Expand Down
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/env', '@babel/preset-typescript']
};
110 changes: 58 additions & 52 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
{
"name": "ethereum-block-by-date",
"version": "1.5.0",
"description": "Get Ethereum block number by a given date. Or blocks by a given period duration.",
"keywords": [
"ethereum",
"blockchain",
"web3",
"eth",
"dapp",
"utilties"
],
"homepage": "https://github.com/monosux/ethereum-block-by-date",
"repository": {
"type": "git",
"url": "https://github.com/monosux/ethereum-block-by-date.git"
},
"bugs": {
"url": "https://github.com/monosux/ethereum-block-by-date/issues"
},
"author": "Sergey Alexeev <[email protected]>",
"license": "MIT",
"main": "./lib/ethereum-block-by-date.js",
"dependencies": {
"moment": "^2.30.1"
},
"scripts": {
"build": "rimraf lib && babel src -d lib",
"test": "npm run build && mocha && npm run lint",
"lint": "eslint src",
"prettier": "prettier src --write",
"style": "yarn lint && yarn prettier"
},
"devDependencies": {
"@babel/cli": "^7.24.8",
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
"chai": "^4.5.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"ethers": "^6.13.2",
"ethers-v5": "npm:[email protected]",
"mocha": "^10.7.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"viem": "^2.18.7",
"web3": "^4.11.1",
"web3-v1": "npm:[email protected]"
},
"browserslist": [
"last 2 chrome versions",
"maintained node versions"
]
"name": "ethereum-block-by-date",
"version": "1.5.0",
"description": "Get Ethereum block number by a given date. Or blocks by a given period duration.",
"keywords": [
"ethereum",
"blockchain",
"web3",
"eth",
"dapp",
"utilties"
],
"homepage": "https://github.com/monosux/ethereum-block-by-date",
"repository": {
"type": "git",
"url": "https://github.com/monosux/ethereum-block-by-date.git"
},
"bugs": {
"url": "https://github.com/monosux/ethereum-block-by-date/issues"
},
"author": "Sergey Alexeev <[email protected]>",
"license": "MIT",
"main": "./lib/ethereum-block-by-date.js",
"dependencies": {
"moment": "^2.30.1"
},
"scripts": {
"clean": "rimraf lib",
"build": "npm run clean && tsc && babel src --out-dir lib --extensions \".ts\"",
"test": "npm run build && mocha -r ts-node/register test/**/*.ts",
"lint": "eslint src",
"prettier": "prettier src --write",
"style": "yarn lint && yarn prettier"
},
"devDependencies": {
"@babel/cli": "^7.26.4",
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@babel/preset-typescript": "^7.26.0",
"@types/bn.js": "^5.1.6",
"@types/chai": "^5.0.1",
"@types/mocha": "^10.0.10",
"@types/node": "^22.10.6",
"chai": "^4.5.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"ethers": "^6.13.2",
"ethers-v5": "npm:[email protected]",
"mocha": "^10.7.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.7.3",
"viem": "^2.18.7"
},
"browserslist": [
"last 2 chrome versions",
"maintained node versions"
]
}
91 changes: 0 additions & 91 deletions src/ethereum-block-by-date.js

This file was deleted.

Loading