npm-package-near-async-block
v1.0.0
Published
npm Package - near-async-block
Readme
npm-package-near-async-block
Utilities for fetching NEAR Protocol block data via the mainnet RPC.
Installation
npm install npm-package-near-async-block
Functions
getBlock(blockId)— Fetch a single block by height, hash, or finality stringgetBlockRange(startHeight, endHeight)— Fetch multiple consecutive blocksgetBlockChunks(blockId)— Get all chunks for a blockgetFinalBlockHeight()— Get the current final block heightwaitForBlock(targetHeight)— Poll until a target block height is reachedgetBlockTransactions(blockId)— Get all transactions in a block
Usage
import { getBlock, getBlockRange, getBlockChunks, getFinalBlockHeight, waitForBlock, getBlockTransactions, } from "npm-package-near-async-block";
// Fetch by finality const finalBlock = await getBlock("final"); const latestBlock = await getBlock("latest");
// Fetch by height or hash const block = await getBlock(12345678);
// Fetch a range of blocks const blocks = await getBlockRange(12345678, 12345690);
// Get chunks for a block const chunks = await getBlockChunks(12345678);
// Get the current final block height const height = await getFinalBlockHeight();
// Wait until a specific block height is reached await waitForBlock(12345700);
// Get all transactions in a block const txs = await getBlockTransactions(12345678);
Notes
- All requests target
https://rpc.mainnet.near.org getBlockRangefetches blocks in parallel; avoid very large rangesgetBlock("latest")maps tooptimisticfinality on the RPC
License
MIT
