Skip to main content
Home

Built and signed on GitHub Actions

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

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
10 months ago (0.1.4)

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

Deno, npm, Yarn, pnpm, Bun from JSR

deno add @nktkas/cosmos-block-for-date
npx jsr 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.

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@nktkas/cosmos-block-for-date

Import symbol

import * as cosmos_block_for_date from "@nktkas/cosmos-block-for-date";
or

Import directly with a jsr specifier

import * as cosmos_block_for_date from "jsr:@nktkas/cosmos-block-for-date";

Add Package

pnpm i jsr:@nktkas/cosmos-block-for-date
or (using pnpm 10.8 or older)
pnpm dlx jsr add @nktkas/cosmos-block-for-date

Import symbol

import * as cosmos_block_for_date from "@nktkas/cosmos-block-for-date";

Add Package

yarn add jsr:@nktkas/cosmos-block-for-date
or (using Yarn 4.8 or older)
yarn dlx jsr add @nktkas/cosmos-block-for-date

Import symbol

import * as cosmos_block_for_date from "@nktkas/cosmos-block-for-date";

Add Package

vlt install jsr:@nktkas/cosmos-block-for-date

Import symbol

import * as cosmos_block_for_date from "@nktkas/cosmos-block-for-date";

Add Package

npx jsr add @nktkas/cosmos-block-for-date

Import symbol

import * as cosmos_block_for_date from "@nktkas/cosmos-block-for-date";

Add Package

bunx jsr add @nktkas/cosmos-block-for-date

Import symbol

import * as cosmos_block_for_date from "@nktkas/cosmos-block-for-date";