This project provides an API for querying blockchain data by date and block number. The API supports multiple blockchain networks and allows you to fetch the block data by providing a timestamp or get the date by providing a block number.
Set the following environment variable before running the project:
cp .env.sample .env
Edit the .env file to include your database connection string:
DATABASE_URL=<Connection string to a database named `rust-block-by-date`>
To run the project locally, ensure you have Rust installed
also have diesel cli, you can check Diesel Docs to see how to do it
use the following command:
diesel migration run # This will run the existing migrations onto your database
cargo run # Runs your project in development mode
/block_by_date
URL: /block_by_date
Method: GET
Query Parameters:
network_id: Chain identifier number of the supported chains (see list below).
timestamp: Timestamp (in seconds) of the block you want (pass 0 if you want the current block).
Supported network_id
values:
42161 => ARBITRUM
43114 => AVALANCHE
1313161554 => AURORA
8453 => BASE
42220 => CELO
1 => ETHEREUM
250 => FANTOM
127 => POLYGON
10 => OPTIMISM
2020 => RONIN
100 => XDAI
Example Request:
GET /block_by_date?network_id=1×tamp=1625097600
/date_by_block
URL: /date_by_block
Method: GET
Query Parameters:
network_id: Chain identifier number of the supported chains (see list above).
block: Block number you want the timestamp for (pass 0 for the current timestamp in seconds).
Example Request:
GET /date_by_block?network_id=1&block=12345678
To build the project for production, use the following command:
cargo build --release
This will create an optimized build of the project in the target/release directory.
Feel free to open issues or submit pull requests if you find bugs or have suggestions for improvements.
This project is licensed under the MIT License.