The Block Time Instance is a TypeScript/JavaScript library designed to facilitate easy and efficient interactions with blockchain data, specifically fetching block information based on timestamps. This library provides methods to interact with blockchain endpoints, allowing developers to find blocks closest to given timestamps seamlessly.
- Simple and intuitive API for interacting with blockchain data.
- Fetch blocks closest to given timestamps.
- Configurable client instances tailored to your specific blockchain endpoint.
To install the package, run the following command in your project directory:
npm i @rarcifa/block-time-instance
Here’s how you can use the Block Time Instance in your project:
import { createBlockTimeClient } from '@rarcifa/block-time-instance';
const blockInstance = createBlockTimeClient({
endpoint: 'CUSTOM_RPC_ENDPOINT', // evm rpc endpoint
});
const getBlock = async (timestamp) => {
try {
const block = await blockInstance.getBlockFromTimestamp(timestamp);
console.log('Block:', block);
} catch (error) {
console.error('Error fetching block:', error);
}
};
getBlock(1718196040);
-
getBlockFromTimestamp(timestamp)
: Fetches the block closest to the given timestamp.
Contributions are welcome! If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
The code in this project is licensed under MIT license.
If you have any questions or comments about the library, please feel free to open an issue or a pull request on our GitHub repository.