npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

meta-explorer

v1.1.2

Published

C3I blockchain SDK to fetch data from multi-chains

Downloads

201

Readme

Blockchain SDK

Blockchain SDK is a Node.js SDK for interacting with blockchain networks using ethers.js. It provides a simple API for retrieving blocks, transactions, network statistics, and sending private transactions. This SDK is designed to work with customizable provider URLs, enabling flexible interactions with various blockchain nodes.

Installation

Install the package using npm:

npm install meta-explorer

Usage

Importing the SDK

To use the SDK, import it into your project:

import meta_explorer from 'meta-explorer';
const { BlockchainSDK } = meta_explorer;

Initializing the SDK

Initialize the SDK with a provider URL and specify the provider type (e.g., 'ethers'):

const blockchainSDK = new BlockchainSDK(providerUrl, 'ethers');

API

The SDK provides several methods to interact with the blockchain network.

Methods

getBlock(blockNumber: string | number)

Retrieves a block by its number or the string 'latest'.

const block = await blockchainSDK.getBlock('latest');

getTransaction(txHash: string)

Fetches transaction details by its hash.

const transaction = await blockchainSDK.getTransaction('0xTransactionHash');

sendPrivateTransaction(from: string, to: string, value: string, gas: string, options: object)

Sends a private transaction to a specified address with optional privacy options.

const receipt = await blockchainSDK.sendPrivateTransaction(from, to, value, gas, { privateFor, privacyFlag });

getAddressDetails(address: string)

Fetches balance and transaction details for a specific address.

const details = await blockchainSDK.getAddressDetails('0xAddress');

getNetworkStats()

Retrieves network statistics, such as the current block number and other metrics.

const networkStats = await blockchainSDK.getNetworkStats();

getBlockGasUsed(blockNumber: number | 'latest')

Fetches the gas used in a specific block.

const gasUsed = await blockchainSDK.getBlockGasUsed('latest');

getBlockMiner(blockNumber: string | number)

Fetches the miner of a specific block.

const miner = await blockchainSDK.getBlockMiner('latest');

getBlockWithTransactions(blockNumber: string | number)

Fetches a block along with its transactions.

const blockWithTransactions = await blockchainSDK.getBlockWithTransactions('latest');

loadBlocksInTimeFrame(startBlock: number, blocksPerPage: number)

Loads blocks within a specified timeframe.

const blocks = await blockchainSDK.loadBlocksInTimeFrame(1000000, 100);

getBlockTransactionCount(blockHashOrBlockNumber: string | number | 'latest')

Fetches the transaction count of a specific block.

const transactionCount = await blockchainSDK.getBlockTransactionCount('latest');

Example Usage

Here’s a basic example of using the SDK to retrieve the latest block, fetch transactions within a block, and send a private transaction:

import BlockchainSDK from 'meta-explorer';

const providerUrl = 'https://your.provider.url';
const blockchainSDK = new BlockchainSDK(providerUrl, 'ethers');

async function main() {
    // Retrieve the latest block
    const latestBlock = await blockchainSDK.getBlock('latest');
    console.log('Latest Block:', latestBlock);

    // Fetch a transaction by its hash
    const txHash = '0xTransactionHash';
    const transaction = await blockchainSDK.getTransaction(txHash);
    console.log('Transaction:', transaction);
}

main().catch(console.error);

Error Handling

The SDK throws custom errors defined in the BlockchainError enum. Handle these errors using try-catch blocks:

try {
    const block = await blockchainSDK.getBlock('latest');
} catch (error) {
    console.error('Error retrieving block:', error);
}

License

This project is licensed under the C3I License.