0.1.3 • Published 11 months ago

@nktkas/cosmos-block-for-date v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Cosmos Block By Date

Get Cosmos block number by a given date, using CosmWasmClient.

This library is a fork of eth-block-for-date adapted for the Cosmos blockchain.

Installation

NPM

npm i @nktkas/cosmos-block-for-date

Deno, Yarn, pnpm, Bun from JSR

deno add @nktkas/cosmos-block-for-date
yarn dlx jsr add @nktkas/cosmos-block-for-date
pnpm dlx jsr add @nktkas/cosmos-block-for-date
bunx jsr add @nktkas/cosmos-block-for-date

Usage

import { CosmosDater } from "@nktkas/cosmos-block-for-date";
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";

const client = await CosmWasmClient.connect("YOUR_RPC_URL");
const dater = new CosmosDater(client);

let block = await dater.getBlock(
    new Date("2023-07-20T13:20:40Z"), // Date, required.
    true, // Block after, optional. Search for the nearest block before or after the given date. True by default.
    false, // Refresh boundaries, optional. Recheck the latest block before request. False by default
);

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.